dimanche 31 décembre 2017

Laravel-5 whereHas Clouse dosen't work as expected

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