Jump to content

nacha

Members
  • Posts

    1
  • Joined

  • Last visited

nacha's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. what's wrong in my code what can I change to make it work because for exemple if I have 3 products have same brand so in brand filter display the brand 3 times (gucci ,gucci,gucci with checkbox) and it's same for other filters and the checkbox not functional how to make it work ,should I add jquery but i don't know how please help I want when check one or multiple (size,color,brand) with checkbox display the products related to the product filters(size,color,brand) (for exemple check size :xl and color:red display products of xl and red)help please thank you and this is categorycontroller public function show($slug) { $category = $this->categoryRepository->findBySlug($slug); $pagination = 15; if (request()->category) { $products = Product::with('categories')->whereHas('categories', function ($query) { $query->whereIn('id', request('category'))->OrderBy('id', 'desc')->paginate($pagination); }); }; if (request()->brand) { $products = Product::where('brand_id', request('brand'))->OrderBy('id', 'desc')->paginate($pagination); }; if (request()->size) { $products = ProductAttribute::where('id','=',1)->where('id', request('size'))->OrderBy('id', 'desc')->paginate($pagination); }; if (request()->color) { $products = ProductAttribute::where('id','=',2)->where('id', request('color'))->OrderBy('id', 'desc')->paginate($pagination); }; $products = Product::OrderBy('name', 'asc')->paginate($pagination); return view('site.pages.category', compact('category','products')); } } category.blade.php: for brand: @foreach($products as $product) <div class="card-body"> <form> <label for="brand_id" class="form-check"> <input class="form-check-input" id="brand_id" value="{{$product->brand->id}}" type="checkbox"> <span class="form-check-label"> {{ $product->brand->name }} </span> </label> for size: @foreach($products as $product) @foreach($product->attributes as $attributeValue) @if ($attributeValue->attribute_id == 1) <form> <label for="size" class="form-check"> <input class="form-check-input" id="attribute" value="{{$attributeValue->value}}" type="checkbox"> <span class="form-check-label"> {{ $attributeValue->value }} </span> </label> for color: @foreach($products as $product) @foreach($product->attributes as $attribute) @foreach($product->attributes as $attributeValue) @if ($attribute->id == 2) <form> <label for="color" class="form-check"> <input class="form-check-input" id="{{$attributeValue->id}}" value="{{$attributeValue->value}}" type="checkbox"> <span class="form-check-label"> {{ $attributeValue->value}} </span> </label> like this image
×
×
  • Create New...