public $categories = [];
public function mount()
{
// Fetch categories from the database
$this->categories = Category::all();
}
#[Url]
public $selected_categories = []; // Add this line to manage selected categories
// public $showCategoryFilter = false; // Add this line
//public function toggleCategoryFilter()
//{
// $this->showCategoryFilter = !$this->showCategoryFilter;
//}
public function render() {
$productQuery = Product::query()->where('is_visible', 1);
//'products' => Product::query()
// ->where('is_visible', 1)
// ->when(!empty($this->selectedCategories), function (Builder $query) {
// $query->whereHas('categories', function($query) {
// $query->whereIn('category_id', $this->selectedCategories);
// });
// })
// ->paginate(6),
return view('livewire.products-page', [
'products' => $productQuery->paginate(6),
'brands' => Brand::where('is_visible', 1)->get(['id', 'name', 'slug']),
'categories' => Category::where('is_visible', 1)->get(['id', 'name', 'slug']),
]);
}
}