@@ -75,6 +75,8 @@ protected function buildClass($name)
7575
7676 $ stub = $ this ->addMoreTo ($ stub );
7777
78+ $ stub = $ this ->replaceModelNamespace ($ stub );
79+
7880 return $ this ->replaceNamespace ($ stub , $ name )->replaceClass ($ stub , $ name );
7981 }
8082
@@ -89,7 +91,7 @@ protected function createFactory()
8991
9092 $ this ->call ('crud:factory ' , [
9193 'name ' => "{$ factory }Factory " ,
92- '--model ' => $ this ->qualifyClass ($ this ->getNameInput ()),
94+ '--model ' => $ this ->qualifyModel ($ this ->getNameInput ()),
9395 ]);
9496 }
9597
@@ -210,7 +212,28 @@ public function getPath($name)
210212 $ content = $ this ->getComposer ();
211213 $ name = Str::replaceFirst ($ this ->rootNamespace (), '' , $ name );
212214 $ path = getcwd () . $ this ->devPath ();
213- $ path = $ content ->type === 'project ' ? $ path . '/app/ ' : $ path . '/src/ ' ;
215+ $ path = $ content ->type === 'project ' ? $ path . '/app/Models/ ' : $ path . '/src/Models / ' ;
214216 return $ path . str_replace ('\\' , '/ ' , $ name ) . '.php ' ;
215217 }
218+
219+ public function replaceModelNamespace ($ stub )
220+ {
221+ return str_replace ('DummyNamespace ' , $ this ->rootNamespace () . 'Models ' , $ stub );
222+ }
223+
224+ protected function qualifyModel (string $ model )
225+ {
226+ $ model = ltrim ($ model , '\\/ ' );
227+
228+ $ model = str_replace ('/ ' , '\\' , $ model );
229+
230+ $ rootNamespace = $ this ->rootNamespace ();
231+
232+ if (Str::startsWith ($ model , $ rootNamespace )) {
233+ return $ model ;
234+ }
235+ return is_dir ($ this ->projectPath () . 'Models ' )
236+ ? $ rootNamespace . 'Models \\' . $ model
237+ : $ rootNamespace . $ model ;
238+ }
216239}
0 commit comments