Skip to content

Commit d014d47

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

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/Console/GenerateCommand.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -377,25 +377,28 @@ public function enumValues($model, $table, $name)
377377
return "[]";
378378
}
379379

380-
$driver = $model->getConnection()->getDriverName();
380+
$connection = $model->getConnection();
381+
$driver = $connection->getDriverName();
381382
$values = null;
382383

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

386388
preg_match_all("/'([^']+)'/", $type, $matches);
387389

388390
$values = isset($matches[1]) ? $matches[1] : array();
389391

390392
return "['" . implode("', '", $values) . "']";
391393
} 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-
"));
394+
$types = DB::connection($connection)
395+
->select(DB::raw("
396+
select matches[1]
397+
from pg_constraint, regexp_matches(consrc, '''(.+?)''', 'g') matches
398+
where contype = 'c'
399+
and conname = '{$table}_{$name}_check'
400+
and conrelid = 'public.{$table}'::regclass;
401+
"));
399402

400403
$values = array();
401404

0 commit comments

Comments
 (0)