From 7530bd61bdac0dfe817bac0c07c16927013ced99 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sat, 27 Feb 2021 13:11:44 -0800 Subject: [PATCH] Maintain other scopes when using the custom "search" filter --- app/JsonApi/Adapters/FoodAdapter.php | 4 +--- app/JsonApi/Adapters/RecipeAdapter.php | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/JsonApi/Adapters/FoodAdapter.php b/app/JsonApi/Adapters/FoodAdapter.php index 591372a..413751b 100644 --- a/app/JsonApi/Adapters/FoodAdapter.php +++ b/app/JsonApi/Adapters/FoodAdapter.php @@ -43,14 +43,12 @@ class FoodAdapter extends AbstractAdapter */ protected function filter($query, Collection $filters) { + $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}%"); } - else { - $this->filterWithScopes($query, $filters); - } } /** diff --git a/app/JsonApi/Adapters/RecipeAdapter.php b/app/JsonApi/Adapters/RecipeAdapter.php index 87833da..174da17 100644 --- a/app/JsonApi/Adapters/RecipeAdapter.php +++ b/app/JsonApi/Adapters/RecipeAdapter.php @@ -44,14 +44,12 @@ class RecipeAdapter extends AbstractAdapter */ protected function filter($query, Collection $filters) { + $this->filterWithScopes($query, $filters->except('search')); if ($term = $filters->get('search')) { $query->where('recipes.name', 'like', "%{$term}%") ->orWhere('recipes.description', 'like', "%{$term}%") ->orWhere('recipes.source', 'like', "%{$term}%"); } - else { - $this->filterWithScopes($query, $filters); - } } /**