@@ -39,6 +39,13 @@ class ScaffoldAuthenticationControllers extends Command
39
39
*/
40
40
protected $ namespace = null ;
41
41
42
+ /**
43
+ * Models namespace
44
+ *
45
+ * @var string
46
+ */
47
+ protected $ modelNamespace = null ;
48
+
42
49
/**
43
50
* @var Illuminate\Filesystem\Filesystem
44
51
*/
@@ -54,6 +61,8 @@ public function __construct()
54
61
parent ::__construct ();
55
62
56
63
$ this ->namespace = self ::DEFAULT_NAMESPACE ;
64
+
65
+ $ this ->modelNamespace = self ::DEFAULT_NAMESPACE ;
57
66
58
67
$ this ->filesystem = new Filesystem ;
59
68
}
@@ -88,6 +97,8 @@ protected function identifyApplicationNamespace()
88
97
if ($ this ->namespace !== self ::DEFAULT_NAMESPACE ) {
89
98
$ this ->comment ("Using [ $ this ->namespace ] as application namespace. " );
90
99
}
100
+
101
+ $ this ->modelNamespace = is_dir (app_path ('Models ' )) ? $ this ->namespace .'\\Models ' : $ this ->namespace ;
91
102
} catch (RuntimeException $ ex ) {
92
103
$ this ->warn ("Unable to identity the application namespace, assuming [ $ this ->namespace ]. " );
93
104
}
@@ -126,12 +137,12 @@ protected function scaffoldModels()
126
137
mkdir ($ directory , 0755 , true );
127
138
}
128
139
129
- // TODO: make it Models folder aware
140
+ $ useModelsDirectory = is_dir ( app_path ( ' Models ' ));
130
141
131
142
collect ($ this ->filesystem ->allFiles (__DIR__ .'/../../../stubs/Identities/Models ' ))
132
- ->each (function (SplFileInfo $ file ) {
143
+ ->each (function (SplFileInfo $ file ) use ( $ useModelsDirectory ) {
133
144
$ modelName = Str::replaceLast ('.stub ' , '.php ' , $ file ->getFilename ());
134
- $ model = app_path ($ modelName );
145
+ $ model = $ useModelsDirectory ? app_path ( ' Models/ ' . $ modelName ) : app_path ($ modelName );
135
146
136
147
if (file_exists ($ model ) && ! $ this ->option ('force ' )) {
137
148
if ($ this ->confirm ("The [ $ modelName] file already exists. Do you want to replace it? " )) {
@@ -188,7 +199,7 @@ protected function compileControllerStub($stub)
188
199
protected function compileModelStub ($ stub )
189
200
{
190
201
$ originalNamespaceDeclaration = str_replace ('\\; ' , '; ' , "namespace " .self ::DEFAULT_NAMESPACE .'; ' );
191
- $ newNamespaceDeclaration = str_replace ('\\; ' , '; ' , "namespace $ this ->namespace ; " );
202
+ $ newNamespaceDeclaration = str_replace ('\\; ' , '; ' , "namespace $ this ->modelNamespace ; " );
192
203
193
204
return str_replace (
194
205
$ originalNamespaceDeclaration ,
0 commit comments