From 14b47d40e838d3962982c273ae7d4702755e8b50 Mon Sep 17 00:00:00 2001 From: Mekan1206 Date: Mon, 4 May 2026 13:34:54 +0500 Subject: [PATCH] WIP --- .../Controllers/Api/V1/Filters/FilterController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/V1/Filters/FilterController.php b/app/Http/Controllers/Api/V1/Filters/FilterController.php index 25d9773..e0e848d 100644 --- a/app/Http/Controllers/Api/V1/Filters/FilterController.php +++ b/app/Http/Controllers/Api/V1/Filters/FilterController.php @@ -46,7 +46,7 @@ class FilterController extends Controller } if ($this->shouldFilterByCollection()) { - return $this->categoriesFor(); + return $this->categoriesFor($this->request->collection_id, 'collection'); } if ($this->shouldFilterByBrand()) { @@ -54,7 +54,7 @@ class FilterController extends Controller } if ($this->shouldFilterByChannel()) { - return $this->filterByCategoryResource(Channel::find($this->request->channel_id)); + return $this->filterByCategoryResource($this->request->channel_id, 'category'); } return Category::query()->where('is_visible', true)->ordered()->get(['id', 'parent_id', 'name']); @@ -115,20 +115,20 @@ class FilterController extends Controller /** * Categories for a resource */ - private function categoriesFor($resource) + private function categoriesFor(int $id, string $type) { return DB::table('categories as c') ->select('c.id', 'c.parent_id', 'c.name') ->where('c.is_visible', true) - ->whereExists(function ($query) { + ->whereExists(function ($query) use ($id, $type) { $query->select(DB::raw(1)) ->from('product_has_relations as phr_cat') ->join('products as p', 'p.id', '=', 'phr_cat.product_id') ->join('product_has_relations as phr_chan', 'phr_chan.product_id', '=', 'p.id') ->whereColumn('phr_cat.productable_id', 'c.id') ->where('phr_cat.productable_type', 'category') - ->where('phr_chan.productable_type', 'channel') - ->where('phr_chan.productable_id', 6) + ->where('phr_chan.productable_type', $type) + ->where('phr_chan.productable_id', $id) ->where('p.is_visible', true) ->whereNull('p.parent_id') ->where('p.stock', '>', 0);