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
10 changes: 5 additions & 5 deletions src/Console/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;


class GenerateCommand extends Command
{
/**
Expand Down Expand Up @@ -368,9 +367,11 @@ public static function enumValues($table, $name)
if ($table === null) {
return "[]";
}

$type = DB::select(DB::raw('SHOW COLUMNS FROM ' . $table . ' WHERE Field = "' . $name . '"'))[0]->Type;

if (env('DB_HOST') == 'postgres') {
Copy link

@TheDoctor0 TheDoctor0 May 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's a good idea to check the database host to determine whether it's PostgreSQL. This check should be for pgsql driver:

if (env('DB_CONNECTION') === 'pgsql') {

$type = DB::select(DB::raw('SELECT column_name,data_type FROM information_schema.columns WHERE table_name = \'' . $table . '\' AND column_name = \'' . $name . '\''))[0]->data_type;
} else {
$type = DB::select(DB::raw('SHOW COLUMNS FROM ' . $table . ' WHERE Field = "' . $name . '"'))[0]->Type;
}
preg_match_all("/'([^']+)'/", $type, $matches);

$values = isset($matches[1]) ? $matches[1] : array();
Expand All @@ -394,5 +395,4 @@ protected function createFactory($class)

return $content;
}

}