diff --git a/src/Uniqueway/Repositories/Criteria/FuzzyGroupSearch.php b/src/Uniqueway/Repositories/Criteria/FuzzyGroupSearch.php deleted file mode 100644 index ab09d6e..0000000 --- a/src/Uniqueway/Repositories/Criteria/FuzzyGroupSearch.php +++ /dev/null @@ -1,58 +0,0 @@ -query = $query; - $this->attributes = $attributes; - } - - /** - * @param $model - * @param Repository $repository - * @return mixed - */ - public function apply($model, Repository $repository) - { - if (empty($this->query)) { - return $model; - } - - return $model->where(function ($query) { - foreach ($this->attributes as $attribute) { - if ($attribute == 'id' && preg_match('/^\d+$/', $this->query)) { - $query->orWhere($attribute, '=', $this->query); - } else { - $pattern = '%' . $this->query . '%'; - $query->orWhere($attribute, 'LIKE', $pattern); - } - } - }); - } -} diff --git a/src/Uniqueway/Repositories/Criteria/FuzzySearch.php b/src/Uniqueway/Repositories/Criteria/FuzzySearch.php index 86d5090..6319fe2 100644 --- a/src/Uniqueway/Repositories/Criteria/FuzzySearch.php +++ b/src/Uniqueway/Repositories/Criteria/FuzzySearch.php @@ -44,18 +44,15 @@ public function apply($model, Repository $repository) return $model; } - $where = 'where'; - foreach ($this->attributes as $attribute) { - if ($attribute == 'id' && preg_match('/^\d+$/', $this->query)) { - $model = $model->$where($attribute, '=', $this->query); - } else { - $pattern = '%' . $this->query . '%'; - $model = $model->$where($attribute, 'LIKE', $pattern); + return $model->where(function ($query) { + foreach ($this->attributes as $attribute) { + if ($attribute == 'id' && preg_match('/^\d+$/', $this->query)) { + $query->orWhere($attribute, '=', $this->query); + } else { + $pattern = '%' . $this->query . '%'; + $query->orWhere($attribute, 'LIKE', $pattern); + } } - - $where = 'orWhere'; - } - - return $model; + }); } }