File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
src/Illuminate/Database/Console/Factories Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ protected function buildClass($name)
6262 {
6363 $ namespaceModel = $ this ->option ('model ' )
6464 ? $ this ->qualifyModel ($ this ->option ('model ' ))
65- : $ this ->qualifyModel (' Model ' );
65+ : $ this ->qualifyModel ($ this -> guessModelName ( $ name ) );
6666
6767 $ model = class_basename ($ namespaceModel );
6868
@@ -102,6 +102,31 @@ protected function getPath($name)
102102 return $ this ->laravel ->databasePath ().'/factories/ ' .str_replace ('\\' , '/ ' , $ name ).'.php ' ;
103103 }
104104
105+ /**
106+ * Guess the model name from the Factory name or return a default model name.
107+ *
108+ * @param string $name
109+ * @return string
110+ */
111+ protected function guessModelName ($ name )
112+ {
113+ if (Str::endsWith ($ name , 'Factory ' )) {
114+ $ name = substr ($ name , 0 , -7 );
115+ }
116+
117+ $ modelName = $ this ->qualifyModel (class_basename ($ name ));
118+
119+ if (class_exists ($ modelName )) {
120+ return $ modelName ;
121+ }
122+
123+ if (is_dir (app_path ('Models/ ' ))) {
124+ return 'App\Models\Model ' ;
125+ }
126+
127+ return 'App\Model ' ;
128+ }
129+
105130 /**
106131 * Get the console command options.
107132 *
You can’t perform that action at this time.
0 commit comments