@@ -93,9 +93,7 @@ protected function createPluginDirectories(string $pluginPath): void
9393 ];
9494
9595 foreach ($ directories as $ directory ) {
96- !File::exists ($ directory ) && File::makeDirectory ($ directory , 0755 , true );
97-
98- $ this ->line ('Created directory: ' . basename ($ directory ));
96+ !File::exists ($ directory ) && File::makeDirectory ($ directory , 0755 , true ) && $ this ->line ('Created directory: ' . basename ($ directory ));
9997 }
10098 }
10199
@@ -200,6 +198,7 @@ protected function createControllerFile(string $pluginPath, string $pluginName,
200198 }
201199
202200 $ filePath = $ pluginPath . '/Controllers/ ' . $ fileName ;
201+
203202 if (File::exists ($ filePath )) {
204203 $ this ->warn ("Controller file ' {$ fileName }' already exists in plugin ' {$ pluginName }'. Skipping... " );
205204 return ;
@@ -287,7 +286,12 @@ public function index()
287286 }
288287
289288 File::put ($ pluginPath . '/Controllers/ ' . $ fileName , $ content );
289+
290290 $ this ->line ("Created: {$ fileName }" );
291+
292+ if ($ this ->option ('route ' )) {
293+ $ this ->createRouteFile ($ pluginPath , $ pluginName , $ controllerName );
294+ }
291295 }
292296
293297 protected function createServiceFile (string $ pluginPath , string $ pluginName ): void
@@ -660,7 +664,7 @@ public function color(): string
660664 $ this ->line ("Created enum: {$ filePath }" );
661665 }
662666
663- protected function createConcernFile (string $ pluginPath , string $ pluginName ,string $ trait ): void
667+ protected function createConcernFile (string $ pluginPath , string $ pluginName , string $ trait ): void
664668 {
665669 $ filePath = "{$ pluginPath }/Concerns/ {$ trait }.php " ;
666670 $ traitName = ucfirst ($ trait );
@@ -733,11 +737,6 @@ protected function createAdditionalComponents(string $pluginPath, string $plugin
733737 $ this ->createViewFile ($ pluginPath , $ pluginName , $ viewType , $ this ->option ('view ' ));
734738 }
735739
736- if ($ this ->option ('route ' )) {
737- $ controllerName = $ this ->option ('controller ' ) ?? $ pluginName ;
738- $ this ->createRouteFile ($ pluginPath , $ pluginName , $ controllerName );
739- }
740-
741740 if ($ this ->option ('enum ' )) {
742741 $ this ->createEnumFile ($ pluginPath , $ pluginName , $ this ->option ('enum ' ));
743742 }
@@ -755,15 +754,20 @@ protected function createRouteFile(string $pluginPath, string $pluginName, ?stri
755754 $ filePath = $ pluginPath . '/ ' . $ fileName ;
756755
757756 $ pluginNameLower = strtolower ($ pluginName );
758- $ controllerClass = $ controllerName . 'Controller ' ;
757+
758+ if (str_ends_with ($ controllerName , 'Controller ' )) {
759+ $ controllerClass = Str::studly ($ controllerName );
760+ } else {
761+ $ controllerClass = Str::studly ("{$ controllerName }Controller " );
762+ }
759763
760764 $ newRoutes = "
761765Route::controller( {$ controllerClass }::class)->group(function () {
762766 Route::get('/', 'index')->name(' {$ pluginNameLower }.index');
763767 Route::post('/', 'store')->name(' {$ pluginNameLower }.store');
764- Route::get('/{{id} }', 'show')->name(' {$ pluginNameLower }.show');
765- Route::put('/{{id} }', 'update')->name(' {$ pluginNameLower }.update');
766- Route::delete('/{{id} }', 'destroy')->name(' {$ pluginNameLower }.destroy');
768+ Route::get('/{id }', 'show')->name(' {$ pluginNameLower }.show');
769+ Route::put('/{id }', 'update')->name(' {$ pluginNameLower }.update');
770+ Route::delete('/{id }', 'destroy')->name(' {$ pluginNameLower }.destroy');
767771}); " ;
768772
769773 if (File::exists ($ filePath )) {
0 commit comments