mercredi 23 mai 2018

How to filter products by range price and attributes in laravel 5.5

products table: id,name,price

attributes table: id,name,label,type{select or text}

attribute_values table: id,attribute_id,name,label

attribute_product_attribute_value table(pivot table): product_id,attribute_id,attribute_value_id,value

my code:

if ($category = CategoryProduct::getCategoryByValue('id', decode(\request()
   ->input('category')))) {
        $query = $category->products()->where('price', '>=', 
          (int)\request()->input('min_price'))->where('price', '<='
          , (int)\request()->input('max_price'))->whereHas('atts', function 
            ($query) {
           foreach (Input::get('att_filter') as $atts) {
             foreach ($atts as $index => $value) {
             $query->atts()->where('att_id', decode($index))
           - >where('sub_att_id', decode($value));

                            }
                       }

                    })->get();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire