1 year ago

filter with MorphToMany

Posted 1 year 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');

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.