Skip to content

Commit fee9793

Browse files
committed
Use model connection when selecting model field enum values.
1 parent d524e70 commit fee9793

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/Console/GenerateCommand.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -381,26 +381,28 @@ public function enumValues($model, $table, $name)
381381
$values = null;
382382

383383
if ($driver === 'mysql') {
384-
$type = DB::select(DB::raw('SHOW COLUMNS FROM ' . $table . ' WHERE Field = "' . $name . '"'))[0]->Type;
384+
$type = DB::connection($model->getConnectionName())
385+
->select(DB::raw('SHOW COLUMNS FROM ' . $table . ' WHERE Field = "' . $name . '"'))[0]->Type;
385386

386387
preg_match_all("/'([^']+)'/", $type, $matches);
387388

388-
$values = isset($matches[1]) ? $matches[1] : array();
389-
390-
return "['" . implode("', '", $values) . "']";
389+
$values = isset($matches[1]) ? $matches[1] : null;
391390
} else if ($driver === 'pgsql') {
392-
$types = DB::select(DB::raw("
393-
select matches[1]
394-
from pg_constraint, regexp_matches(consrc, '''(.+?)''', 'g') matches
395-
where contype = 'c'
396-
and conname = '{$table}_{$name}_check'
397-
and conrelid = 'public.{$table}'::regclass;
398-
"));
399-
400-
$values = array();
401-
402-
foreach ($types as $type){
403-
$values[] = $type->matches;
391+
$types = DB::connection($model->getConnectionName())
392+
->select(DB::raw("
393+
select matches[1]
394+
from pg_constraint, regexp_matches(consrc, '''(.+?)''', 'g') matches
395+
where contype = 'c'
396+
and conname = '{$table}_{$name}_check'
397+
and conrelid = 'public.{$table}'::regclass;
398+
"));
399+
400+
if (count($types)) {
401+
$values = array();
402+
403+
foreach ($types as $type){
404+
$values[] = $type->matches;
405+
}
404406
}
405407
}
406408

0 commit comments

Comments
 (0)