This commit is contained in:
Mekan1206
2026-05-03 18:36:49 +05:00
parent 774ac3c622
commit 1b467108de

View File

@@ -62,29 +62,29 @@ class FilterController extends Controller
private function brands() private function brands()
{ {
if ($this->shouldFilterByBrand()) { if ($this->shouldFilterByBrand()) {
return Brand::query()->where('id', $this->request->brand_id)->get(['id', 'name']); return Brand::where('id', $this->request->brand_id)->get(['id', 'name']);
} }
if ($this->shouldFilterByCategory()) { if ($this->shouldFilterByCategory()) {
$brands = Category::query()->find($this->request->category_id)->products() $brands = Category::find($this->request->category_id)->products()
->where('products.is_visible', true) ->where('products.is_visible', true)
->where('products.parent_id', null) ->where('products.parent_id', null)
->where('products.stock', '>', 0) ->where('products.stock', '>', 0)
->distinct('products.brand_id') ->distinct('products.brand_id')
->pluck('products.brand_id'); ->pluck('products.brand_id');
return Brand::query()->whereIntegerInRaw('id', $brands)->get(['id', 'name']); return Brand::whereIntegerInRaw('id', $brands)->get(['id', 'name']);
} }
if ($this->shouldFilterByCollection()) { if ($this->shouldFilterByCollection()) {
$brands = Collection::query()->find($this->request->collection_id)->products() $brands = Collection::find($this->request->collection_id)->products()
->where('products.is_visible', true) ->where('products.is_visible', true)
->where('products.parent_id', null) ->where('products.parent_id', null)
->where('products.stock', '>', 0) ->where('products.stock', '>', 0)
->distinct('products.brand_id') ->distinct('products.brand_id')
->pluck('products.brand_id'); ->pluck('products.brand_id');
return Brand::query()->whereIntegerInRaw('id', $brands)->get(['id', 'name']); return Brand::whereIntegerInRaw('id', $brands)->get(['id', 'name']);
} }
return Brand::query()->where('is_visible', true)->ordered()->get(['id', 'name']); return Brand::query()->where('is_visible', true)->ordered()->get(['id', 'name']);
@@ -102,18 +102,13 @@ class FilterController extends Controller
->distinct('products.id') ->distinct('products.id')
->pluck('products.id'); ->pluck('products.id');
return Category::query() return Category::where('is_visible', true)
->distinct('categories.id') ->ordered()
->where('is_visible', true) ->join('product_has_relations', 'categories.id', '=', 'product_has_relations.productable_id')
->join('product_has_relations', 'categories.id', '=', 'product_has_relations.productable_id') ->where('product_has_relations.productable_type', '=', 'category')
->where('product_has_relations.productable_type', '=', 'category') ->whereIntegerInRaw('product_has_relations.product_id', $products)
->whereIntegerInRaw('product_has_relations.product_id', $products) ->get(['categories.id', 'categories.parent_id', 'categories.name'])
->get() ->unique('categories.id');
->map(fn ($category) => [
'id' => $category->id,
'parent_id' => $category->parent_id,
'name' => $category->name,
]);
} }
/** /**