@@ -39,6 +39,7 @@ public function generateController()
3939 $ template = str_replace ('{{modelName}} ' , $ this ->model , $ template );
4040 $ template = str_replace ('{{modelNameLower}} ' , strtolower ($ this ->model ), $ template );
4141 $ template = str_replace ('{{modelNameCamel}} ' , Str::camel ($ this ->model ), $ template );
42+ $ template = str_replace ('{{modelNameSpace}} ' , is_dir (base_path ('app/Models ' )) ? 'Models \\' .$ this ->model : $ this ->model , $ template );
4243 file_put_contents (base_path ('app/Http/Controllers/Api/ ' .$ this ->model .'Controller.php ' ), $ template );
4344 $ this ->result = true ;
4445 }
@@ -50,7 +51,7 @@ public function generateResource()
5051 {
5152 $ this ->result = false ;
5253 if (! file_exists (base_path ('app/Http/Resources/ ' .$ this ->model .'Resource.php ' ))) {
53- $ model = app ('App \\' .$ this ->model );
54+ $ model = is_dir ( base_path ( ' app/Models ' )) ? app ( ' App \\ Models \\' . $ this -> model ) : app ('App \\' .$ this ->model );
5455 $ columns = $ model ->getConnection ()->getSchemaBuilder ()->getColumnListing ($ model ->getTable ());
5556 $ print_columns = null ;
5657 foreach ($ columns as $ key => $ column ) {
@@ -82,14 +83,26 @@ public function generateCollection()
8283 public function generateRoute ()
8384 {
8485 $ this ->result = false ;
85- $ template = "Route::apiResource('{{modelNameLower}}', 'Api\{{modelName}}Controller'); " ."\n" ;
86+ if (app ()->version () >= 8 ){
87+ $ nameSpace = "\nuse App\Http\Controllers\Api\{{modelName}}Controller; " ;
88+ $ template = "Route::apiResource('{{modelNameLower}}', {{modelName}}Controller::class); \n" ;
89+ $ nameSpace = str_replace ('{{modelName}} ' , $ this ->model , $ nameSpace );
90+ }else {
91+ $ template = "Route::apiResource('{{modelNameLower}}', 'Api\{{modelName}}Controller'); \n" ;
92+ }
8693 $ route = str_replace ('{{modelNameLower}} ' , Str::camel (Str::plural ($ this ->model )), $ template );
8794 $ route = str_replace ('{{modelName}} ' , $ this ->model , $ route );
8895 if (! strpos (file_get_contents (base_path ('routes/api.php ' )), $ route )) {
8996 file_put_contents (base_path ('routes/api.php ' ), $ route , FILE_APPEND );
97+ if (app ()->version () >= 8 ){
98+ if (! strpos (file_get_contents (base_path ('routes/api.php ' )), $ nameSpace )) {
99+ $ lines = file (base_path ('routes/api.php ' ));
100+ $ lines [0 ] = $ lines [0 ]."\n" .$ nameSpace ;
101+ file_put_contents (base_path ('routes/api.php ' ), $ lines );
102+ }
103+ }
90104 $ this ->result = true ;
91105 }
92-
93106 return $ this ->result ;
94107 }
95108
0 commit comments