33namespace Yajra \DataTables \Generators ;
44
55use Illuminate \Support \Str ;
6+ use Illuminate \Support \Facades \Schema ;
67use Illuminate \Console \GeneratorCommand ;
78use Symfony \Component \Console \Input \InputOption ;
89
@@ -17,6 +18,7 @@ class DataTablesHtmlCommand extends GeneratorCommand
1718 {name : The name of the datatable html.}
1819 {--dom= : The dom of the datatable.}
1920 {--buttons= : The buttons of the datatable.}
21+ {--table= : Scaffold columns from the table.}
2022 {--columns= : The columns of the datatable.} ' ;
2123
2224 /**
@@ -168,6 +170,10 @@ protected function replaceColumns(&$stub)
168170 */
169171 protected function getColumns ()
170172 {
173+ if ($ this ->option ('table ' )) {
174+ return $ this ->parseColumns (Schema::getColumnListing ($ this ->option ('table ' )));
175+ }
176+
171177 if ($ this ->option ('columns ' ) != '' ) {
172178 return $ this ->parseColumns ($ this ->option ('columns ' ));
173179 } else {
@@ -189,7 +195,7 @@ protected function getColumns()
189195 */
190196 protected function parseColumns ($ definition , $ indentation = 12 )
191197 {
192- $ columns = explode (', ' , $ definition );
198+ $ columns = is_array ( $ definition ) ? $ definition : explode (', ' , $ definition );
193199 $ stub = '' ;
194200 foreach ($ columns as $ key => $ column ) {
195201 $ stub .= "Column::make(' {$ column }'), " ;
0 commit comments