duansha3771 2018-05-23 13:46
浏览 90

如何在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(equest()
   ->input('category')))) {
        $query = $category->products()->where('price', '>=', 
          (int)equest()->input('min_price'))->where('price', '<='
          , (int)equest()->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();
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
    • ¥15 onvif+openssl,vs2022编译openssl64
    • ¥15 iOS 自定义输入法-第三方输入法
    • ¥15 很想要一个很好的答案或提示
    • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
    • ¥15 怀疑手机被监控,请问怎么解决和防止
    • ¥15 Qt下使用tcp获取数据的详细操作
    • ¥15 idea右下角设置编码是灰色的
    • ¥15 全志H618ROM新增分区
    • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示