@@ -102,7 +102,7 @@ public function generate(string $table, array $options = []): array
102
102
* @param string $table The database table name
103
103
* @return string The controller class name
104
104
*/
105
- public function getClassName (string $ table ): string
105
+ public function getClassName (string $ table, string $ action = "" ): string
106
106
{
107
107
$ modelName = Str::studly (Str::singular ($ table ));
108
108
return $ modelName . 'Controller ' ;
@@ -123,7 +123,7 @@ public function getNamespace(): string
123
123
*
124
124
* @return string The controller file path
125
125
*/
126
- public function getPath (): string
126
+ public function getPath (string $ path = "" ): string
127
127
{
128
128
return base_path (Config::get ('crud.paths.controllers ' , 'app/Http/Controllers ' ));
129
129
}
@@ -185,7 +185,7 @@ protected function generateApiController(string $table, array $options): string
185
185
{
186
186
$ modelName = Str::studly (Str::singular ($ table ));
187
187
$ className = 'Api ' . $ modelName . 'Controller ' ;
188
-
188
+
189
189
$ apiOptions = array_merge ($ options , ['is_api ' => true ]);
190
190
$ content = $ this ->buildClass ($ table , $ apiOptions , 'api ' );
191
191
@@ -218,19 +218,19 @@ public function buildClass(string $table, array $options, string $type = 'web'):
218
218
{
219
219
$ modelName = Str::studly (Str::singular ($ table ));
220
220
$ modelVariable = Str::camel ($ modelName );
221
-
221
+
222
222
if ($ type === 'api ' ) {
223
223
$ className = 'Api ' . $ modelName . 'Controller ' ;
224
224
$ namespace = $ this ->getNamespace () . '\\Api ' ;
225
225
} else {
226
226
$ className = $ this ->getClassName ($ table );
227
227
$ namespace = $ this ->getNamespace ();
228
228
}
229
-
229
+
230
230
$ modelNamespace = Config::get ('crud.namespaces.models ' , 'App \\Models ' );
231
231
$ serviceClass = $ modelName . 'Service ' ;
232
232
$ serviceNamespace = Config::get ('crud.namespaces.services ' , 'App \\Services ' );
233
-
233
+
234
234
$ stub = $ this ->getStub ($ type );
235
235
236
236
// Setup service injection
@@ -343,7 +343,7 @@ public function __construct({$serviceClass} \$service)
343
343
public function setupRequestValidation (array $ requestClasses ): string
344
344
{
345
345
$ validationCode = "" ;
346
-
346
+
347
347
if (!empty ($ requestClasses )) {
348
348
$ validationCode = " /**
349
349
* Get the appropriate request class for the given action.
@@ -361,7 +361,7 @@ protected function getRequestClass(string \$action): string
361
361
$ validationCode .= " ][ \$action] ?? FormRequest::class;
362
362
} " ;
363
363
}
364
-
364
+
365
365
return $ validationCode ;
366
366
}
367
367
@@ -395,7 +395,7 @@ protected function authorizeAction(\$ability, \$arguments = [])
395
395
public function generateViewRenderingMethods (string $ table ): string
396
396
{
397
397
$ viewPrefix = Str::kebab (Str::plural ($ table ));
398
-
398
+
399
399
return " /**
400
400
* Get the view for the given action.
401
401
*
@@ -586,7 +586,7 @@ public function generateCrudMethods(string $table, string $type, array $options)
586
586
$ modelPluralVariable = Str::camel (Str::plural ($ modelName ));
587
587
$ requestStore = $ modelName . 'StoreRequest ' ;
588
588
$ requestUpdate = $ modelName . 'UpdateRequest ' ;
589
-
589
+
590
590
if ($ type === 'api ' ) {
591
591
return " /**
592
592
* Display a listing of the resource.
@@ -960,7 +960,7 @@ protected function getRequiredImports(
960
960
"{$ requestNamespace }\\{$ modelName }StoreRequest " ,
961
961
"{$ requestNamespace }\\{$ modelName }UpdateRequest " ,
962
962
];
963
-
963
+
964
964
if ($ type === 'api ' ) {
965
965
$ apiImports = [
966
966
'Illuminate\Http\JsonResponse ' ,
@@ -974,15 +974,47 @@ protected function getRequiredImports(
974
974
];
975
975
$ imports = array_merge ($ commonImports , $ webImports );
976
976
}
977
-
977
+
978
978
$ imports = array_unique ($ imports );
979
979
sort ($ imports );
980
-
980
+
981
981
$ importStatements = '' ;
982
982
foreach ($ imports as $ import ) {
983
983
$ importStatements .= "use {$ import }; \n" ;
984
984
}
985
-
985
+
986
986
return $ importStatements ;
987
987
}
988
- }
988
+
989
+ /**
990
+ * Set configuration options for the generator.
991
+ *
992
+ * @param array $options Configuration options
993
+ * @return self Returns the generator instance for method chaining
994
+ */
995
+ public function setOptions (array $ options ): self
996
+ {
997
+ $ this ->options = array_merge ($ this ->options ?? [], $ options );
998
+ return $ this ;
999
+ }
1000
+
1001
+ /**
1002
+ * Get a list of all generated file paths.
1003
+ *
1004
+ * @return array List of generated file paths
1005
+ */
1006
+ public function getGeneratedFiles (): array
1007
+ {
1008
+ return $ this ->generatedFiles ?? [];
1009
+ }
1010
+
1011
+ /**
1012
+ * Determine if the generator supports customization.
1013
+ *
1014
+ * @return bool True if the generator supports customization
1015
+ */
1016
+ public function supportsCustomization (): bool
1017
+ {
1018
+ return true ;
1019
+ }
1020
+ }
0 commit comments