@@ -39,6 +39,13 @@ class ScaffoldAuthenticationControllers extends Command
3939 */
4040 protected $ namespace = null ;
4141
42+ /**
43+ * Models namespace
44+ *
45+ * @var string
46+ */
47+ protected $ modelNamespace = null ;
48+
4249 /**
4350 * @var Illuminate\Filesystem\Filesystem
4451 */
@@ -54,6 +61,8 @@ public function __construct()
5461 parent ::__construct ();
5562
5663 $ this ->namespace = self ::DEFAULT_NAMESPACE ;
64+
65+ $ this ->modelNamespace = self ::DEFAULT_NAMESPACE ;
5766
5867 $ this ->filesystem = new Filesystem ;
5968 }
@@ -88,6 +97,8 @@ protected function identifyApplicationNamespace()
8897 if ($ this ->namespace !== self ::DEFAULT_NAMESPACE ) {
8998 $ this ->comment ("Using [ $ this ->namespace ] as application namespace. " );
9099 }
100+
101+ $ this ->modelNamespace = is_dir (app_path ('Models ' )) ? $ this ->namespace .'\\Models ' : $ this ->namespace ;
91102 } catch (RuntimeException $ ex ) {
92103 $ this ->warn ("Unable to identity the application namespace, assuming [ $ this ->namespace ]. " );
93104 }
@@ -126,12 +137,12 @@ protected function scaffoldModels()
126137 mkdir ($ directory , 0755 , true );
127138 }
128139
129- // TODO: make it Models folder aware
140+ $ useModelsDirectory = is_dir ( app_path ( ' Models ' ));
130141
131142 collect ($ this ->filesystem ->allFiles (__DIR__ .'/../../../stubs/Identities/Models ' ))
132- ->each (function (SplFileInfo $ file ) {
143+ ->each (function (SplFileInfo $ file ) use ( $ useModelsDirectory ) {
133144 $ modelName = Str::replaceLast ('.stub ' , '.php ' , $ file ->getFilename ());
134- $ model = app_path ($ modelName );
145+ $ model = $ useModelsDirectory ? app_path ( ' Models/ ' . $ modelName ) : app_path ($ modelName );
135146
136147 if (file_exists ($ model ) && ! $ this ->option ('force ' )) {
137148 if ($ this ->confirm ("The [ $ modelName] file already exists. Do you want to replace it? " )) {
@@ -188,7 +199,7 @@ protected function compileControllerStub($stub)
188199 protected function compileModelStub ($ stub )
189200 {
190201 $ originalNamespaceDeclaration = str_replace ('\\; ' , '; ' , "namespace " .self ::DEFAULT_NAMESPACE .'; ' );
191- $ newNamespaceDeclaration = str_replace ('\\; ' , '; ' , "namespace $ this ->namespace ; " );
202+ $ newNamespaceDeclaration = str_replace ('\\; ' , '; ' , "namespace $ this ->modelNamespace ; " );
192203
193204 return str_replace (
194205 $ originalNamespaceDeclaration ,
0 commit comments