Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating raw DB queries to include DB prefix. #127

Merged
merged 1 commit into from
Sep 25, 2016
Merged
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
5 changes: 3 additions & 2 deletions src/CrudTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DB;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Config;

trait CrudTrait
{
Expand All @@ -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) {
Expand All @@ -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';
}
Expand Down