@@ -39,6 +39,7 @@ public function generateController()
39
39
$ template = str_replace ('{{modelName}} ' , $ this ->model , $ template );
40
40
$ template = str_replace ('{{modelNameLower}} ' , strtolower ($ this ->model ), $ template );
41
41
$ 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 );
42
43
file_put_contents (base_path ('app/Http/Controllers/Api/ ' .$ this ->model .'Controller.php ' ), $ template );
43
44
$ this ->result = true ;
44
45
}
@@ -50,7 +51,7 @@ public function generateResource()
50
51
{
51
52
$ this ->result = false ;
52
53
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 );
54
55
$ columns = $ model ->getConnection ()->getSchemaBuilder ()->getColumnListing ($ model ->getTable ());
55
56
$ print_columns = null ;
56
57
foreach ($ columns as $ key => $ column ) {
@@ -82,14 +83,26 @@ public function generateCollection()
82
83
public function generateRoute ()
83
84
{
84
85
$ 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
+ }
86
93
$ route = str_replace ('{{modelNameLower}} ' , Str::camel (Str::plural ($ this ->model )), $ template );
87
94
$ route = str_replace ('{{modelName}} ' , $ this ->model , $ route );
88
95
if (! strpos (file_get_contents (base_path ('routes/api.php ' )), $ route )) {
89
96
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
+ }
90
104
$ this ->result = true ;
91
105
}
92
-
93
106
return $ this ->result ;
94
107
}
95
108
0 commit comments