@@ -17,15 +17,15 @@ class MakePantryCommand extends Command
1717 * @var string
1818 */
1919 protected $ signature = '
20- make:pantry {pantry?} {model? }
20+ make:pantry {pantry?} {-- model= : Generate pantry class for given model }
2121 ' ;
2222
2323 /**
2424 * The console command description.
2525 *
2626 * @var string
2727 */
28- protected $ description = 'Create a new pantry ' ;
28+ protected $ description = 'Create a new pantry class. ' ;
2929
3030 /**
3131 * Execute the console command.
@@ -47,7 +47,7 @@ public function handle()
4747 $ modelNamespace = 'App \\Models ' ;
4848
4949 // Pantry Name
50- $ pantry = (string ) Str::of ($ this ->argument ('pantry ' ) ?? $ this ->askRequired ('Pantry (e.g. `UserPantry `) ' , 'pantry ' ))
50+ $ pantry = (string ) Str::of ($ this ->argument ('pantry ' ) ?? $ this ->askRequired ('Pantry (e.g. `FoodPantry `) ' , 'pantry ' ))
5151 ->studly ()
5252 ->trim ('/ ' )
5353 ->trim ('\\' )
@@ -77,12 +77,15 @@ public function handle()
7777 ->append ('.php ' );
7878
7979 // Model Name
80- $ model = (string ) Str::of ($ this ->argument ('model ' ) ?? $ this ->askRequired ('Model (e.g. `User`) ' , 'model ' ))
81- ->studly ()
82- ->trim ('/ ' )
83- ->trim ('\\' )
84- ->trim (' ' )
85- ->replace ('/ ' , '\\' );
80+ $ model = (string ) Str::of ($ className )->replace ('Pantry ' , '' );
81+ if ( $ this ->option ('model ' ) ) {
82+ $ model = (string ) Str::of ($ this ->option ('model ' ) ?? $ this ->askRequired ('Model (e.g. `Food`) ' , 'model ' ))
83+ ->studly ()
84+ ->trim ('/ ' )
85+ ->trim ('\\' )
86+ ->trim (' ' )
87+ ->replace ('/ ' , '\\' );
88+ }
8689
8790 list ($ className , $ namespace ) = $ this ->getClassName ($ model );
8891
@@ -98,6 +101,10 @@ public function handle()
98101 'model ' => $ model ,
99102 'modelNamespace ' => $ modelNamespace ,
100103 ]);
104+
105+ $ this ->info ("Panrty [ {$ path }] created successfully. " );
106+
107+ return static ::SUCCESS ;
101108 }
102109
103110 private function getClassName ($ name ): array
0 commit comments