Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 7 additions & 28 deletions src/Console/ResourceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Encore\Admin\Console;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Schema;

class ResourceGenerator
{
Expand Down Expand Up @@ -83,12 +84,12 @@ public function generateForm()
$output = '';

foreach ($this->getTableColumns() as $column) {
$name = $column->getName();
$name = $column['name'];
if (in_array($name, $reservedColumns)) {
continue;
}
$type = $column->getType()->getName();
$default = $column->getDefault();
$type = $column['type_name'];
$default = $column['default'];

$defaultValue = '';

Expand Down Expand Up @@ -166,7 +167,7 @@ public function generateShow()
$output = '';

foreach ($this->getTableColumns() as $column) {
$name = $column->getName();
$name = $column['name'];

// set column label
$label = $this->formatLabel($name);
Expand All @@ -184,7 +185,7 @@ public function generateGrid()
$output = '';

foreach ($this->getTableColumns() as $column) {
$name = $column->getName();
$name = $column['name'];
$label = $this->formatLabel($name);

$output .= sprintf($this->formats['grid_column'], $name, $label);
Expand Down Expand Up @@ -213,31 +214,9 @@ protected function getReservedColumns()
*/
protected function getTableColumns()
{
if (!$this->model->getConnection()->isDoctrineAvailable()) {
throw new \Exception(
'You need to require doctrine/dbal: ~2.3 in your own composer.json to get database columns. '
);
}

$table = $this->model->getConnection()->getTablePrefix().$this->model->getTable();
/** @var \Doctrine\DBAL\Schema\MySqlSchemaManager $schema */
$schema = $this->model->getConnection()->getDoctrineSchemaManager($table);

// custom mapping the types that doctrine/dbal does not support
$databasePlatform = $schema->getDatabasePlatform();

foreach ($this->doctrineTypeMapping as $doctrineType => $dbTypes) {
foreach ($dbTypes as $dbType) {
$databasePlatform->registerDoctrineTypeMapping($dbType, $doctrineType);
}
}

$database = null;
if (strpos($table, '.')) {
list($database, $table) = explode('.', $table);
}

return $schema->listTableColumns($table, $database);
return Schema::getColumns($table);
}

/**
Expand Down