Skip to content

Commit

Permalink
Phpdoc, fix using eloquent table prefix
Browse files Browse the repository at this point in the history
If you use custom table prefix in laravel orm database configuration you
should set it in query "select (conds) as `{prefix}table`" to avoid
conflicts with other traits like softDeletes (default eloquent trait).
Issue was descripted in
#101
  • Loading branch information
zenn1989 committed Jan 20, 2016
1 parent 054f14f commit b7673e2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/SearchableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
/**
* Trait SearchableTrait
* @package Nicolaslopezj\Searchable
* @property array $searchable
* @property string $table
* @property string $primaryKey
* @method string getTable()
*/
trait SearchableTrait
{
Expand Down Expand Up @@ -314,10 +318,11 @@ protected function addBindingsToQuery(Builder $query, array $bindings) {
* @param \Illuminate\Database\Eloquent\Builder $original
*/
protected function mergeQueries(Builder $clone, Builder $original) {
if($this->getDatabaseDriver() == 'pgsql'){
$original->from(DB::connection($this->connection)->raw("({$clone->toSql()}) as {$this->getTable()}"));
}else{
$original->from(DB::connection($this->connection)->raw("({$clone->toSql()}) as `{$this->getTable()}`"));
$tableName = DB::connection($this->connection)->getTablePrefix() . $this->getTable();
if ($this->getDatabaseDriver() == 'pgsql') {
$original->from(DB::connection($this->connection)->raw("({$clone->toSql()}) as {$tableName}"));
} else {
$original->from(DB::connection($this->connection)->raw("({$clone->toSql()}) as `{$tableName}`"));
}
$original->mergeBindings($clone->getQuery());
}
Expand Down

0 comments on commit b7673e2

Please sign in to comment.