Jump to content

help please how to display products with checkbox(products related to color ,size and brand :filters)


nacha
 Share

Recommended Posts

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

prod.thumb.png.f5aeeece88b9a62556147894e5a7cb37.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...