@@ -40,11 +40,22 @@ public function handle(): int
4040 return E_ERROR ;
4141 }
4242
43- $ this ->handleOptionalMigrationOption ();
43+ if ($ this ->option ('all ' )) {
44+ $ this ->input ->setOption ('controller ' , true );
45+ $ this ->input ->setOption ('factory ' , true );
46+ $ this ->input ->setOption ('migration ' , true );
47+ $ this ->input ->setOption ('request ' , true );
48+ $ this ->input ->setOption ('resource ' , true );
49+ $ this ->input ->setOption ('policy ' , true );
50+ $ this ->input ->setOption ('seed ' , true );
51+ }
52+
4453 $ this ->handleOptionalControllerOption ();
45- $ this ->handleOptionalSeedOption ();
4654 $ this ->handleOptionalFactoryOption ();
55+ $ this ->handleOptionalMigrationOption ();
4756 $ this ->handleOptionalRequestOption ();
57+ $ this ->handleOptionalResourceOption ();
58+ $ this ->handleOptionalSeedOption ();
4859
4960 return 0 ;
5061 }
@@ -53,10 +64,8 @@ public function handle(): int
5364 * Create a proper migration name:
5465 * ProductDetail: product_details
5566 * Product: products
56- *
57- * @return string
5867 */
59- private function createMigrationName ()
68+ protected function createMigrationName (): string
6069 {
6170 $ pieces = preg_split ('/(?=[A-Z])/ ' , $ this ->argument ('model ' ), -1 , PREG_SPLIT_NO_EMPTY );
6271
@@ -74,10 +83,8 @@ private function createMigrationName()
7483
7584 /**
7685 * Get the console command arguments.
77- *
78- * @return array
7986 */
80- protected function getArguments ()
87+ protected function getArguments (): array
8188 {
8289 return [
8390 ['model ' , InputArgument::REQUIRED , 'The name of model will be created. ' ],
@@ -87,25 +94,26 @@ protected function getArguments()
8794
8895 /**
8996 * Get the console command options.
90- *
91- * @return array
9297 */
93- protected function getOptions ()
98+ protected function getOptions (): array
9499 {
95100 return [
96- ['fillable ' , null , InputOption::VALUE_OPTIONAL , 'The fillable attributes. ' , null ],
97- ['migration ' , 'm ' , InputOption::VALUE_NONE , 'Flag to create associated migrations ' , null ],
101+ ['all ' , 'a ' , InputOption::VALUE_NONE , 'Flag to create all associated files ' , null ],
98102 ['controller ' , 'c ' , InputOption::VALUE_NONE , 'Flag to create associated controllers ' , null ],
99- ['seed ' , ' s ' , InputOption::VALUE_NONE , 'Create a new seeder for the model ' , null ],
103+ ['fillable ' , null , InputOption::VALUE_OPTIONAL , 'The fillable attributes. ' , null ],
100104 ['factory ' , 'f ' , InputOption::VALUE_NONE , 'Create a new factory for the model ' , null ],
105+ ['migration ' , 'm ' , InputOption::VALUE_NONE , 'Flag to create associated migrations ' , null ],
101106 ['request ' , 'r ' , InputOption::VALUE_NONE , 'Create a new request for the model ' , null ],
107+ ['resource ' , 'R ' , InputOption::VALUE_NONE , 'Create a new resource for the model ' , null ],
108+ ['policy ' , 'p ' , InputOption::VALUE_NONE , 'Create a new policy for the model ' , null ],
109+ ['seed ' , 's ' , InputOption::VALUE_NONE , 'Create a new seeder for the model ' , null ],
102110 ];
103111 }
104112
105113 /**
106114 * Create the migration file with the given model if migration flag was used
107115 */
108- private function handleOptionalMigrationOption ()
116+ protected function handleOptionalMigrationOption (): void
109117 {
110118 if ($ this ->option ('migration ' ) === true ) {
111119 $ migrationName = 'create_ ' .$ this ->createMigrationName ().'_table ' ;
@@ -116,7 +124,7 @@ private function handleOptionalMigrationOption()
116124 /**
117125 * Create the controller file for the given model if controller flag was used
118126 */
119- private function handleOptionalControllerOption ()
127+ protected function handleOptionalControllerOption (): void
120128 {
121129 if ($ this ->option ('controller ' ) === true ) {
122130 $ controllerName = "{$ this ->getModelName ()}Controller " ;
@@ -130,27 +138,8 @@ private function handleOptionalControllerOption()
130138
131139 /**
132140 * Create a seeder file for the model.
133- *
134- * @return void
135141 */
136- protected function handleOptionalSeedOption ()
137- {
138- if ($ this ->option ('seed ' ) === true ) {
139- $ seedName = "{$ this ->getModelName ()}Seeder " ;
140-
141- $ this ->call ('module:make-seed ' , array_filter ([
142- 'name ' => $ seedName ,
143- 'module ' => $ this ->argument ('module ' ),
144- ]));
145- }
146- }
147-
148- /**
149- * Create a seeder file for the model.
150- *
151- * @return void
152- */
153- protected function handleOptionalFactoryOption ()
142+ protected function handleOptionalFactoryOption (): void
154143 {
155144 if ($ this ->option ('factory ' ) === true ) {
156145 $ this ->call ('module:make-factory ' , array_filter ([
@@ -162,10 +151,8 @@ protected function handleOptionalFactoryOption()
162151
163152 /**
164153 * Create a request file for the model.
165- *
166- * @return void
167154 */
168- protected function handleOptionalRequestOption ()
155+ protected function handleOptionalRequestOption (): void
169156 {
170157 if ($ this ->option ('request ' ) === true ) {
171158 $ requestName = "{$ this ->getModelName ()}Request " ;
@@ -178,9 +165,36 @@ protected function handleOptionalRequestOption()
178165 }
179166
180167 /**
181- * @return mixed
168+ * Create a resource file for the model.
182169 */
183- protected function getTemplateContents ()
170+ protected function handleOptionalResourceOption (): void
171+ {
172+ if ($ this ->option ('resource ' ) === true ) {
173+ $ resourceName = "{$ this ->getModelName ()}Resource " ;
174+
175+ $ this ->call ('module:make-resource ' , array_filter ([
176+ 'name ' => $ resourceName ,
177+ 'module ' => $ this ->argument ('module ' ),
178+ ]));
179+ }
180+ }
181+
182+ /**
183+ * Create a seeder file for the model.
184+ */
185+ protected function handleOptionalSeedOption (): void
186+ {
187+ if ($ this ->option ('seed ' ) === true ) {
188+ $ seedName = "{$ this ->getModelName ()}Seeder " ;
189+
190+ $ this ->call ('module:make-seed ' , array_filter ([
191+ 'name ' => $ seedName ,
192+ 'module ' => $ this ->argument ('module ' ),
193+ ]));
194+ }
195+ }
196+
197+ protected function getTemplateContents (): string
184198 {
185199 $ module = $ this ->laravel ['modules ' ]->findOrFail ($ this ->getModuleName ());
186200
@@ -196,10 +210,7 @@ protected function getTemplateContents()
196210 ]))->render ();
197211 }
198212
199- /**
200- * @return mixed
201- */
202- protected function getDestinationFilePath ()
213+ protected function getDestinationFilePath (): string
203214 {
204215 $ path = $ this ->laravel ['modules ' ]->getModulePath ($ this ->getModuleName ());
205216
@@ -208,18 +219,12 @@ protected function getDestinationFilePath()
208219 return $ path .$ modelPath ->getPath ().'/ ' .$ this ->getModelName ().'.php ' ;
209220 }
210221
211- /**
212- * @return mixed|string
213- */
214- private function getModelName ()
222+ private function getModelName (): string
215223 {
216224 return Str::studly ($ this ->argument ('model ' ));
217225 }
218226
219- /**
220- * @return string
221- */
222- private function getFillable ()
227+ private function getFillable (): string
223228 {
224229 $ fillable = $ this ->option ('fillable ' );
225230
0 commit comments