Skip to content

Commit 7c9c362

Browse files
committed
Add option to get columns from the given table.
1 parent f4e6439 commit 7c9c362

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Generators/DataTablesHtmlCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Yajra\DataTables\Generators;
44

55
use Illuminate\Support\Str;
6+
use Illuminate\Support\Facades\Schema;
67
use Illuminate\Console\GeneratorCommand;
78
use 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

Comments
 (0)