Skip to content

Commit

Permalink
Fix wrong global scopes' bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre committed May 17, 2018
1 parent 940b886 commit e7abed4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/SearchableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,14 @@ protected function mergeQueries(Builder $clone, Builder $original) {
$original->from(DB::connection($this->connection)->raw("({$clone->toSql()}) as `{$tableName}`"));
}

$original->setBindings(
array_merge_recursive(
$clone->getBindings(),
$original->getBindings()
)
// First create a new array merging bindings
$mergedBindings = array_merge_recursive(
$clone->getBindings(),
$original->getBindings()
);

// Then apply bindings WITHOUT global scopes which are already included. If not, there is a strange behaviour
// with some scope's bindings remaning
$original->withoutGlobalScopes()->setBindings($mergedBindings);
}
}

2 comments on commit e7abed4

@manavo
Copy link
Contributor

@manavo manavo commented on e7abed4 Dec 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks in Laravel 4.2, withoutGlobalScopes doesn't exist

@manavo
Copy link
Contributor

@manavo manavo commented on e7abed4 Dec 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw that there is #176 for that already

Please sign in to comment.