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; + }); } }