From 98cbc59e1107ba588adec652f9210817ab629af9 Mon Sep 17 00:00:00 2001 From: Benjamin Lau Date: Mon, 2 Oct 2017 14:47:16 +0200 Subject: [PATCH] fix broken bindings after searchable trait is applied --- src/SearchableTrait.php | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/SearchableTrait.php b/src/SearchableTrait.php index a3db5ca..49ce834 100644 --- a/src/SearchableTrait.php +++ b/src/SearchableTrait.php @@ -1,7 +1,6 @@ makeGroupBy($query); - $clone_bindings = $query->getBindings(); - $query->setBindings([]); - - $this->addBindingsToQuery($query, $this->search_bindings); - $this->addBindingsToQuery($query, $clone_bindings); - if(is_callable($restriction)) { $query = $restriction($query); } @@ -227,8 +220,7 @@ protected function makeGroupBy(Builder $query) */ protected function addSelectsToQuery(Builder $query, array $selects) { - $selects = new Expression('max(' . implode(' + ', $selects) . ') as relevance'); - $query->addSelect($selects); + $query->selectRaw('max(' . implode(' + ', $selects) . ') as relevance', $this->search_bindings); } /** @@ -316,22 +308,6 @@ protected function getCaseCompare($column, $compare, $relevance) { return '(case when ' . $field . ' then ' . $relevance . ' else 0 end)'; } - /** - * Adds the bindings to the query. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param array $bindings - */ - protected function addBindingsToQuery(Builder $query, array $bindings) { - $count = $this->getDatabaseDriver() != 'mysql' ? 2 : 1; - for ($i = 0; $i < $count; $i++) { - foreach($bindings as $binding) { - $type = $i == 1 ? 'select' : 'having'; - $query->addBinding($binding, $type); - } - } - } - /** * Merge our cloned query builder with the original one. *