I want when check one or multiple category with checkbox display the products related to the categories(product filters) (for exemple check dress and basket display products of dress and basket) like this
and this is my code:
category.blade.php:
<form>
@foreach($products as $product)
@foreach ($product->categories as $category)
<label class="form-check">
<input class="form-check-input" name="category[]" value="{{ $category->id }}" type="checkbox">
<span class="form-check-label">
<span class="float-right badge badge-light round"></span> {{ $category->name }}
</span>
</label>
@endforeach
@endforeach
</form>
and this is categorycontroller:
public function show($slug)
{
$category = $this->categoryRepository->findBySlug($slug);
$pagination = 2;
if (request()->category) {
$products = Product::with('categories')->whereHas('categories', function ($query) {
$query->whereIn('id', request('category'));
});
};
$products = Product::OrderBy('id', 'desc')->paginate($pagination);
return view('site.pages.category', compact('category','products'));
}
}
how to change this to make it work thank you