From b7bb15b1e43030c47ee2e85262b016328fa4102d Mon Sep 17 00:00:00 2001 From: Olayinka Azeez Date: Fri, 27 Sep 2024 14:54:23 +0100 Subject: [PATCH 1/2] fix search functionality for buckets --- src/Http/Controllers/Admin/FeaturedController.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Http/Controllers/Admin/FeaturedController.php b/src/Http/Controllers/Admin/FeaturedController.php index 7c98401a8..48ae968aa 100644 --- a/src/Http/Controllers/Admin/FeaturedController.php +++ b/src/Http/Controllers/Admin/FeaturedController.php @@ -5,6 +5,7 @@ use A17\Twill\Models\Feature; use A17\Twill\Repositories\Behaviors\HandleMedias; use A17\Twill\Repositories\Behaviors\HandleTranslations; +use A17\Twill\Services\Listings\Filters\FreeTextSearch; use Illuminate\Config\Repository as Config; use Illuminate\Contracts\Foundation\Application; use Illuminate\Database\DatabaseManager as DB; @@ -153,10 +154,13 @@ private function getFeaturedSources(Request $request, $featuredSection, $search $repository = $this->getRepository($module, $bucketable['repository'] ?? null); $translated = classHasTrait($repository, HandleTranslations::class); $withImage = classHasTrait($repository, HandleMedias::class); + $appliedFilters = []; if ($search) { - $searchField = $bucketable['searchField'] ?? ($translated ? 'title' : '%title'); - $scopes[$searchField] = $search; + $searchField = $bucketable['searchField'] ?? 'title'; + $appliedFilters[] = FreeTextSearch::make() + ->searchFor($search) + ->searchColumns([$searchField]); } $items = $fetchedModules[$module] ?? $repository->get( @@ -164,7 +168,8 @@ private function getFeaturedSources(Request $request, $featuredSection, $search ($bucketable['scopes'] ?? []) + ($scopes ?? []), $bucketable['orders'] ?? [], $bucketable['per_page'] ?? $request->get('offset') ?? 10, - true + true, + $appliedFilters, )->appends('bucketable', $module); $fetchedModules[$module] = $items; From 073be75ac0d19fa24e649ee43ad8ffc4ad58781a Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Mon, 14 Oct 2024 19:03:25 +0200 Subject: [PATCH 2/2] Remove unused $scopes variable --- src/Http/Controllers/Admin/FeaturedController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/Controllers/Admin/FeaturedController.php b/src/Http/Controllers/Admin/FeaturedController.php index 48ae968aa..58c38686e 100644 --- a/src/Http/Controllers/Admin/FeaturedController.php +++ b/src/Http/Controllers/Admin/FeaturedController.php @@ -165,7 +165,7 @@ private function getFeaturedSources(Request $request, $featuredSection, $search $items = $fetchedModules[$module] ?? $repository->get( $bucketable['with'] ?? [], - ($bucketable['scopes'] ?? []) + ($scopes ?? []), + $bucketable['scopes'] ?? [], $bucketable['orders'] ?? [], $bucketable['per_page'] ?? $request->get('offset') ?? 10, true,