66
77use Illuminate \Support \Facades \File ;
88use Illuminate \Support \Str ;
9+ use Mrdebug \Crudgen \Services \Livewire \MakeDatatableService ;
910use Mrdebug \Crudgen \Services \MakeControllerService ;
1011use Mrdebug \Crudgen \Services \MakeGlobalService ;
1112use Mrdebug \Crudgen \Services \MakeMigrationService ;
@@ -20,7 +21,7 @@ class MakeCrud extends Command
2021 *
2122 * @var string
2223 */
23- protected $ signature = 'make:crud {crud_name} {columns} ' ;
24+ protected $ signature = 'make:crud {crud_name} {columns} {{--with-livewire}} ' ;
2425
2526 /**
2627 * The console command description.
@@ -38,6 +39,7 @@ class MakeCrud extends Command
3839 public MakeRequestService $ makeRequestService ;
3940 public MakeMigrationService $ makeMigrationService ;
4041 public MakeModelService $ makeModelService ;
42+ public MakeDatatableService $ makeDatatableService ;
4143 public MakeGlobalService $ makeGlobalService ;
4244 public PathsAndNamespacesService $ pathsAndNamespacesService ;
4345
@@ -46,6 +48,7 @@ public function __construct(
4648 MakeRequestService $ makeRequestService ,
4749 MakeMigrationService $ makeMigrationService ,
4850 MakeModelService $ makeModelService ,
51+ MakeDatatableService $ makeDatatableService ,
4952 MakeGlobalService $ makeGlobalService ,
5053 PathsAndNamespacesService $ pathsAndNamespacesService
5154 )
@@ -55,6 +58,7 @@ public function __construct(
5558 $ this ->makeRequestService = $ makeRequestService ;
5659 $ this ->makeMigrationService = $ makeMigrationService ;
5760 $ this ->makeModelService = $ makeModelService ;
61+ $ this ->makeDatatableService = $ makeDatatableService ;
5862 $ this ->makeGlobalService = $ makeGlobalService ;
5963 $ this ->pathsAndNamespacesService = $ pathsAndNamespacesService ;
6064 }
@@ -68,6 +72,7 @@ public function handle()
6872 {
6973 // we create our variables to respect the naming conventions
7074 $ crudName = ucfirst ($ this ->argument ('crud_name ' ));
75+ $ withLivewire = $ this ->option ('with-livewire ' );
7176 $ namingConvention = $ this ->makeGlobalService ->getNamingConvention ($ crudName );
7277 $ columns = $ this ->makeGlobalService ->parseColumns ($ this ->argument ('columns ' ));
7378 $ laravelNamespace = $ this ->laravel ->getNamespace ();
@@ -78,7 +83,18 @@ public function handle()
7883
7984 ************************************************************************* */
8085
81- $ this ->makeControllerService ->makeCompleteControllerFile ($ namingConvention , $ columns , $ laravelNamespace );
86+ $ this ->makeControllerService ->makeCompleteControllerFile ($ namingConvention , $ columns , $ laravelNamespace , $ withLivewire );
87+
88+ /* *************************************************************************
89+
90+ DATATABLE
91+
92+ ************************************************************************* */
93+ if ($ withLivewire )
94+ {
95+ $ columnNameInLivewireSearch = $ this ->setNameColumnInLivewireSearch ($ columns );
96+ $ this ->makeDatatableService ->makeCompleteDatatableFile ($ namingConvention , $ laravelNamespace , $ columnNameInLivewireSearch );
97+ }
8298
8399 /* *************************************************************************
84100
@@ -91,10 +107,13 @@ public function handle()
91107 'make:views ' ,
92108 [
93109 'directory ' => $ crudName ,
94- 'columns ' => $ this ->argument ('columns ' )
110+ 'columns ' => $ this ->argument ('columns ' ),
111+ '--with-livewire ' => $ withLivewire ,
112+ 'searchableColumn ' => $ columnNameInLivewireSearch ?? null
95113 ]
96114 );
97115
116+
98117 /* *************************************************************************
99118
100119 REQUEST
@@ -170,4 +189,15 @@ private function setNameModelRelationship($type, $namingConvention, $infos)
170189 else
171190 $ this ->setNameModelRelationship ($ type , $ namingConvention , $ infos );
172191 }
192+
193+ private function setNameColumnInLivewireSearch (array $ columns )
194+ {
195+ $ choices = $ this ->makeGlobalService ->getColumnsNameFromInputConsole ($ columns );
196+ $ columnInSearch = $ this ->choice (
197+ 'Please specify which column you would like to use in the Livewire search? ' ,
198+ $ choices
199+ );
200+
201+ return $ columnInSearch ;
202+ }
173203}
0 commit comments