Maintain other scopes when using the custom "search" filter

This commit is contained in:
Christopher C. Wells 2021-02-27 13:28:05 -08:00 committed by Christopher Charbonneau Wells
parent 7530bd61bd
commit a32cb2e72d
2 changed files with 8 additions and 4 deletions

View File

@ -45,9 +45,11 @@ class FoodAdapter extends AbstractAdapter
{
$this->filterWithScopes($query, $filters->except('search'));
if ($term = $filters->get('search')) {
$query->where('foods.name', 'like', "%{$term}%")
->orWhere('foods.detail', 'like', "%{$term}%")
->orWhere('foods.brand', 'like', "%{$term}%");
$query->where(function ($query) use ($term) {
$query->where('foods.name', 'like', "%{$term}%")
->orWhere('foods.detail', 'like', "%{$term}%")
->orWhere('foods.brand', 'like', "%{$term}%");
});
}
}

View File

@ -46,9 +46,11 @@ class RecipeAdapter extends AbstractAdapter
{
$this->filterWithScopes($query, $filters->except('search'));
if ($term = $filters->get('search')) {
$query->where('recipes.name', 'like', "%{$term}%")
$query->where(function ($query) use ($term) {
$query->where('recipes.name', 'like', "%{$term}%")
->orWhere('recipes.description', 'like', "%{$term}%")
->orWhere('recipes.source', 'like', "%{$term}%");
});
}
}