where('active', true); if ($request->filled('q')) { $query->where('name', 'like', '%'.$request->q.'%'); } if ($request->filled('min_price')) { $query->where('base_price', '>=', $request->min_price); } if ($request->filled('max_price')) { $query->where('base_price', '<=', $request->max_price); } $products = $query->orderBy('sort_order')->paginate(16); $categories = Category::whereNull('parent_id')->where('active', true)->get(); return view('shop.products.index', compact('products', 'categories')); } public function category(string $slug) { $category = Category::where('slug', $slug)->where('active', true)->firstOrFail(); $categoryIds = collect([$category->id])->merge($category->children->pluck('id')); $products = Product::with(['images'])->where('active', true)->whereIn('category_id', $categoryIds)->orderBy('sort_order')->paginate(16); return view('shop.products.index', compact('products', 'category')); } public function show(string $slug) { $product = Product::with(['images', 'category', 'variants.attributeValues.attribute']) ->where('slug', $slug) ->where('active', true) ->firstOrFail(); $related = Product::where('category_id', $product->category_id) ->where('id', '!=', $product->id) ->where('active', true) ->take(4)->get(); return view('shop.products.show', compact('product', 'related')); } }