@@ -36,6 +36,9 @@ public function execute(InputInterface $input, OutputInterface $output): int
3636 $ this ->input ->setOption ('factory ' , true );
3737 $ this ->input ->setOption ('seed ' , true );
3838 $ this ->input ->setOption ('migration ' , true );
39+ $ this ->input ->setOption ('controller ' , true );
40+ $ this ->input ->setOption ('policy ' , true );
41+ $ this ->input ->setOption ('resource ' , true );
3942 }
4043
4144 if ($ this ->input ->getOption ('factory ' )) {
@@ -50,6 +53,15 @@ public function execute(InputInterface $input, OutputInterface $output): int
5053 $ this ->createSeeder ();
5154 }
5255
56+ if ($ this ->input ->getOption ('controller ' ) || $ this ->input ->getOption ('resource ' ) || $ this ->input ->getOption ('api ' )) {
57+ $ this ->createController ();
58+ } elseif ($ this ->input ->getOption ('requests ' )) {
59+ $ this ->createFormRequests ();
60+ }
61+
62+ if ($ this ->input ->getOption ('policy ' )) {
63+ $ this ->createPolicy ();
64+ }
5365 return 0 ;
5466 }
5567
@@ -84,6 +96,11 @@ protected function getOptions(): array
8496 ['force ' , null , InputOption::VALUE_NONE , 'Create the class even if the model already exists ' ],
8597 ['migration ' , 'm ' , InputOption::VALUE_NONE , 'Create a new migration file for the model ' ],
8698 ['seed ' , 's ' , InputOption::VALUE_NONE , 'Create a new seeder for the model ' ],
99+ ['controller ' , 'c ' , InputOption::VALUE_NONE , 'Create a new controller for the model ' ],
100+ ['policy ' , null , InputOption::VALUE_NONE , 'Create a new policy for the model ' ],
101+ ['resource ' , 'r ' , InputOption::VALUE_NONE , 'Indicates if the generated controller should be a resource controller ' ],
102+ ['api ' , null , InputOption::VALUE_NONE , 'Indicates if the generated controller should be an API resource controller ' ],
103+ ['requests ' , 'R ' , InputOption::VALUE_NONE , 'Create new form request classes and use them in the resource controller ' ],
87104 ];
88105 }
89106
@@ -126,6 +143,52 @@ protected function createSeeder()
126143 ]);
127144 }
128145
146+ /**
147+ * Create a controller for the model.
148+ */
149+ protected function createController ()
150+ {
151+ $ controller = Str::studly ($ this ->input ->getArgument ('name ' ));
152+
153+ $ modelName = $ this ->qualifyClass ($ this ->getNameInput ());
154+
155+ $ this ->call ('make:controller ' , array_filter ([
156+ 'name ' => "{$ controller }Controller " ,
157+ '--model ' => $ this ->input ->getOption ('resource ' ) || $ this ->input ->getOption ('api ' ) ? $ modelName : null ,
158+ '--api ' => $ this ->input ->getOption ('api ' ),
159+ '--requests ' => $ this ->input ->getOption ('requests ' ) || $ this ->input ->getOption ('all ' ),
160+ ]));
161+ }
162+
163+ /**
164+ * Create the form requests for the model.
165+ */
166+ protected function createFormRequests ()
167+ {
168+ $ request = Str::studly ($ this ->input ->getArgument ('name ' ));
169+
170+ $ this ->call ('make:request ' , [
171+ 'name ' => "Store {$ request }Request " ,
172+ ]);
173+
174+ $ this ->call ('make:request ' , [
175+ 'name ' => "Update {$ request }Request " ,
176+ ]);
177+ }
178+
179+ /**
180+ * Create a policy file for the model.
181+ */
182+ protected function createPolicy ()
183+ {
184+ $ policy = Str::studly ($ this ->input ->getArgument ('name ' ));
185+
186+ $ this ->call ('make:policy ' , [
187+ 'name ' => "{$ policy }Policy " ,
188+ '--model ' => $ policy ,
189+ ]);
190+ }
191+
129192 protected function call (string $ command , array $ parameters = []): int
130193 {
131194 return $ this ->getApplication ()->doRun (
0 commit comments