@@ -43,20 +43,15 @@ public function handle()
4343 parent ::handle ();
4444
4545 if ($ this ->option ('builder ' )) {
46+ $ columns = config ('datatables-buttons.generator.columns ' , 'id,add your columns,created_at,updated_at ' );
47+ $ buttons = config ('datatables-buttons.generator.buttons ' , 'create,export,print,reset,reload ' );
48+ $ dom = config ('datatables-buttons.generator.dom ' , 'Bfrtip ' );
49+
4650 $ this ->call ('datatables:html ' , [
4751 'name ' => $ this ->getNameInput (),
48- '--columns ' => $ this ->option ('columns ' ) ?: $ this ->laravel ['config ' ]->get (
49- 'datatables-buttons.generator.columns ' ,
50- 'id,add your columns,created_at,updated_at '
51- ),
52- '--buttons ' => $ this ->option ('buttons ' ) ?: $ this ->laravel ['config ' ]->get (
53- 'datatables-buttons.generator.buttons ' ,
54- 'create,export,print,reset,reload '
55- ),
56- '--dom ' => $ this ->option ('dom ' ) ?: $ this ->laravel ['config ' ]->get (
57- 'datatables-buttons.generator.dom ' ,
58- 'Bfrtip '
59- ),
52+ '--columns ' => $ this ->option ('columns ' ) ?: $ columns ,
53+ '--buttons ' => $ this ->option ('buttons ' ) ?: $ buttons ,
54+ '--dom ' => $ this ->option ('dom ' ) ?: $ dom ,
6055 '--table ' => $ this ->option ('table ' ),
6156 ]);
6257 }
@@ -95,7 +90,9 @@ protected function buildClass($name)
9590 protected function replaceFilename (string &$ stub ): static
9691 {
9792 $ stub = str_replace (
98- 'DummyFilename ' , preg_replace ('#datatable$#i ' , '' , $ this ->getNameInput ()), $ stub
93+ 'DummyFilename ' ,
94+ (string ) preg_replace ('#datatable$#i ' , '' , $ this ->getNameInput ()),
95+ $ stub
9996 );
10097
10198 return $ this ;
@@ -123,7 +120,14 @@ protected function replaceAction(string &$stub): static
123120 */
124121 protected function getAction (): string
125122 {
126- return $ this ->option ('action ' ) ?: Str::lower ($ this ->getNameInput ()).'.action ' ;
123+ /** @var string $action */
124+ $ action = $ this ->option ('action ' );
125+
126+ if ($ action ) {
127+ return $ action ;
128+ }
129+
130+ return Str::lower ($ this ->getNameInput ()).'.action ' ;
127131 }
128132
129133 /**
@@ -151,7 +155,7 @@ protected function replaceDOM(string &$stub): static
151155 {
152156 $ stub = str_replace (
153157 'DummyDOM ' ,
154- $ this ->option ('dom ' ) ?: $ this -> laravel [ ' config ' ]-> get ('datatables-buttons.generator.dom ' , 'Bfrtip ' ),
158+ $ this ->option ('dom ' ) ?: config ('datatables-buttons.generator.dom ' , 'Bfrtip ' ),
155159 $ stub
156160 );
157161
@@ -180,16 +184,19 @@ protected function replaceButtons(string &$stub): static
180184 */
181185 protected function getButtons (): string
182186 {
183- if ($ this ->option ('buttons ' ) != '' ) {
184- return $ this ->parseButtons ($ this ->option ('buttons ' ));
185- } else {
186- return $ this ->parseButtons (
187- $ this ->laravel ['config ' ]->get (
188- 'datatables-buttons.generator.buttons ' ,
189- 'create,export,print,reset,reload '
190- )
191- );
187+ /** @var string $buttons */
188+ $ buttons = $ this ->option ('buttons ' );
189+
190+ if ($ buttons ) {
191+ return $ this ->parseButtons ($ buttons );
192192 }
193+
194+ return $ this ->parseButtons (
195+ config (
196+ 'datatables-buttons.generator.buttons ' ,
197+ 'create,export,print,reset,reload '
198+ )
199+ );
193200 }
194201
195202 /**
@@ -243,22 +250,23 @@ protected function replaceColumns(string &$stub): static
243250 */
244251 protected function getColumns (): string
245252 {
253+ /** @var string $table */
246254 $ table = $ this ->option ('table ' );
247255
248256 if ($ table ) {
249257 return $ this ->parseColumns (Schema::getColumnListing ($ table ));
250258 }
251259
252- if ($ this ->option ('columns ' ) != '' ) {
253- return $ this ->parseColumns ($ this ->option ('columns ' ));
260+ /** @var string $columns */
261+ $ columns = $ this ->option ('columns ' );
262+
263+ if ($ columns ) {
264+ return $ this ->parseColumns ($ columns );
254265 }
255266
256- return $ this ->parseColumns (
257- $ this ->laravel ['config ' ]->get (
258- 'datatables-buttons.generator.columns ' ,
259- 'id,add your columns,created_at,updated_at '
260- )
261- );
267+ $ columns = config ('datatables-buttons.generator.columns ' , 'id,add your columns,created_at,updated_at ' );
268+
269+ return $ this ->parseColumns ($ columns );
262270 }
263271
264272 /**
@@ -332,7 +340,7 @@ protected function qualifyClass($name)
332340 */
333341 protected function getDefaultNamespace ($ rootNamespace ): string
334342 {
335- return $ rootNamespace .'\\' .$ this -> laravel [ ' config ' ]-> get ('datatables-buttons.namespace.base ' , 'DataTables ' );
343+ return $ rootNamespace .'\\' .config ('datatables-buttons.namespace.base ' , 'DataTables ' );
336344 }
337345
338346 /**
@@ -359,11 +367,15 @@ protected function getModel(): string
359367 {
360368 $ name = $ this ->getNameInput ();
361369 $ rootNamespace = $ this ->laravel ->getNamespace ();
362- $ model = $ this ->option ('model ' ) == '' || $ this ->option ('model-namespace ' );
363- $ modelNamespace = $ this ->option ('model-namespace ' ) ? $ this ->option ('model-namespace ' ) : $ this ->laravel ['config ' ]->get ('datatables-buttons.namespace.model ' );
364370
365- if ($ this ->option ('model ' ) != '' ) {
366- return $ this ->option ('model ' );
371+ /** @var string $modelFromOption */
372+ $ modelFromOption = $ this ->option ('model ' );
373+
374+ $ model = $ modelFromOption == '' || $ this ->option ('model-namespace ' );
375+ $ modelNamespace = $ this ->option ('model-namespace ' ) ? $ this ->option ('model-namespace ' ) : config ('datatables-buttons.namespace.model ' );
376+
377+ if ($ modelFromOption ) {
378+ return $ modelFromOption ;
367379 }
368380
369381 // check if model namespace is not set in command and Models directory already exists then use that directory in namespace.
@@ -398,15 +410,14 @@ protected function replaceModelImport(string &$stub): static
398410 */
399411 protected function getStub (): string
400412 {
401- $ config = $ this ->laravel ['config ' ];
402413 $ stub = 'datatables.stub ' ;
403414
404415 if ($ this ->option ('builder ' )) {
405416 $ stub = 'builder.stub ' ;
406417 }
407418
408- return $ config-> get ('datatables-buttons.stub ' )
409- ? base_path ().$ config-> get ('datatables-buttons.stub ' )."/ { $ stub} "
419+ return config ('datatables-buttons.stub ' )
420+ ? base_path ().config ('datatables-buttons.stub ' )."/ $ stub "
410421 : __DIR__ ."/stubs/ {$ stub }" ;
411422 }
412423}
0 commit comments