diff --git a/src/CrudTrait.php b/src/CrudTrait.php index ec7e22cb3a..57a713e777 100644 --- a/src/CrudTrait.php +++ b/src/CrudTrait.php @@ -4,6 +4,7 @@ use DB; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Config; trait CrudTrait { @@ -16,7 +17,7 @@ trait CrudTrait public static function getPossibleEnumValues($field_name) { $instance = new static(); // create an instance of the model to be able to get the table name - $type = DB::select(DB::raw('SHOW COLUMNS FROM '.$instance->getTable().' WHERE Field = "'.$field_name.'"'))[0]->Type; + $type = DB::select(DB::raw('SHOW COLUMNS FROM '.Config::get('database.connections.'.env('DB_CONNECTION').'.prefix').$instance->getTable().' WHERE Field = "'.$field_name.'"'))[0]->Type; preg_match('/^enum\((.*)\)$/', $type, $matches); $enum = []; foreach (explode(',', $matches[1]) as $value) { @@ -29,7 +30,7 @@ public static function getPossibleEnumValues($field_name) public static function isColumnNullable($column_name) { $instance = new static(); // create an instance of the model to be able to get the table name - $answer = DB::select(DB::raw("SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$instance->getTable()."' AND COLUMN_NAME='".$column_name."' AND table_schema='".env('DB_DATABASE')."'"))[0]; + $answer = DB::select(DB::raw("SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".Config::get('database.connections.'.env('DB_CONNECTION').'.prefix').$instance->getTable()."' AND COLUMN_NAME='".$column_name."' AND table_schema='".env('DB_DATABASE')."'"))[0]; return $answer->IS_NULLABLE === 'YES'; }