laravel-5 wherehas子句没有按预期工作

jum4pzuy  于 2021-06-25  发布在  Mysql
关注(0)|答案(0)|浏览(209)

我有 categories 以及 products table。它们与多对多的关系有关。。我想按类别和选定的价格范围得到产品,但wherehas条款不起作用

$products = Product::whereHas('categories',function ($query) use ($slug){
$query->where('category_slug',$slug);
})->whereBetween('price',[100,200])->get();

类别模型;

public function products(){
return $this->belongsToMany('App\Product','category_product','category_id','product_id');
 }

产品型号;

public function categories() {
return $this->belongsToMany('App\Category','category_product','product_id','category_id');
    }


那么,我在这里犯了什么错?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题