I have categories
and products
tables. They are related with Many to Many relationships.. I want to get products by categories but whereHas clause dosen't work
$products = Product::whereHas('categories',function ($query) use ($slug){
$query->where('category_name',$slug);
})->whereBetween('price',[100,200])->get();
Category Model;
public function products(){
return $this->belongsToMany('App\Product','category_product','category_id','product_id');
}
So, what is my mistake in here ?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2Cw9NqE
via IFTTT
Aucun commentaire:
Enregistrer un commentaire