Maintain other scopes when using the custom "search" filter

This commit is contained in:
Christopher C. Wells 2021-02-27 13:11:44 -08:00 committed by Christopher Charbonneau Wells
parent a14b58483a
commit 7530bd61bd
2 changed files with 2 additions and 6 deletions

View File

@ -43,14 +43,12 @@ class FoodAdapter extends AbstractAdapter
*/ */
protected function filter($query, Collection $filters) protected function filter($query, Collection $filters)
{ {
$this->filterWithScopes($query, $filters->except('search'));
if ($term = $filters->get('search')) { if ($term = $filters->get('search')) {
$query->where('foods.name', 'like', "%{$term}%") $query->where('foods.name', 'like', "%{$term}%")
->orWhere('foods.detail', 'like', "%{$term}%") ->orWhere('foods.detail', 'like', "%{$term}%")
->orWhere('foods.brand', 'like', "%{$term}%"); ->orWhere('foods.brand', 'like', "%{$term}%");
} }
else {
$this->filterWithScopes($query, $filters);
}
} }
/** /**

View File

@ -44,14 +44,12 @@ class RecipeAdapter extends AbstractAdapter
*/ */
protected function filter($query, Collection $filters) protected function filter($query, Collection $filters)
{ {
$this->filterWithScopes($query, $filters->except('search'));
if ($term = $filters->get('search')) { if ($term = $filters->get('search')) {
$query->where('recipes.name', 'like', "%{$term}%") $query->where('recipes.name', 'like', "%{$term}%")
->orWhere('recipes.description', 'like', "%{$term}%") ->orWhere('recipes.description', 'like', "%{$term}%")
->orWhere('recipes.source', 'like', "%{$term}%"); ->orWhere('recipes.source', 'like', "%{$term}%");
} }
else {
$this->filterWithScopes($query, $filters);
}
} }
/** /**