diff --git a/app/JsonApi/Adapters/FoodAdapter.php b/app/JsonApi/Adapters/FoodAdapter.php index 67814c6..591372a 100644 --- a/app/JsonApi/Adapters/FoodAdapter.php +++ b/app/JsonApi/Adapters/FoodAdapter.php @@ -19,7 +19,11 @@ class FoodAdapter extends AbstractAdapter /** * {@inheritdoc} */ - protected $filterScopes = []; + protected $filterScopes = [ + 'tags' => 'withAllTags', + 'tags.all' => 'withAllTags', + 'tags.any' => 'withAnyTags', + ]; /** * {@inheritdoc} diff --git a/app/JsonApi/Adapters/RecipeAdapter.php b/app/JsonApi/Adapters/RecipeAdapter.php index 55eff0d..87833da 100644 --- a/app/JsonApi/Adapters/RecipeAdapter.php +++ b/app/JsonApi/Adapters/RecipeAdapter.php @@ -20,7 +20,11 @@ class RecipeAdapter extends AbstractAdapter /** * {@inheritdoc} */ - protected $filterScopes = []; + protected $filterScopes = [ + 'tags' => 'withAllTags', + 'tags.all' => 'withAllTags', + 'tags.any' => 'withAnyTags', + ]; /** * {@inheritdoc} diff --git a/resources/views/components/search-view.blade.php b/resources/views/components/search-view.blade.php index ea99daf..150aef8 100644 --- a/resources/views/components/search-view.blade.php +++ b/resources/views/components/search-view.blade.php @@ -42,9 +42,11 @@ size: 12, morePages: false, searchTerm: '{{ $defaultSearch ?? null }}', + filterTag: null, reset() { this.number = 1; this.searchTerm = null; + this.filterTag = null; this.morePages = false; }, loadMore() { @@ -52,6 +54,9 @@ if (this.searchTerm) { url += `&filter[search]=${this.searchTerm}`; } + if (this.filterTag) { + url += `&filter[tags]=${this.filterTag}`; + } fetch(url) .then(response => response.json()) .then(data => { @@ -69,14 +74,13 @@ this.reset(); if (e.target.value !== '') { this.searchTerm = e.target.value; - this.loadMore(); - } - else { - this.loadMore(); } + this.loadMore(); }, filterByTag(e) { - console.log(e.target.text); + this.reset(); + this.filterTag = e.target.text; + this.loadMore(); } } }