haizone
529
13
Eloquent

filter with MorphToMany

Posted 11 months ago by haizone

i have a MorphToMany with categories and products

and i get the products belongs the category like that:

$products = $category->products()->with('specValues')->get();

now i whant to use filter and get with a fild i have in specValues ( the specValues is a morphMany in my product model)

and i didnt fix that i try:

$products->whereHas('specValues', function ($q){
         $q->where('id', '316');
 })->get();

and i try:

$products->where('specValues.id', '316'); 

but its didnt work somone know how i can fix that?

Please sign in or create an account to participate in this conversation.