i need only those products where variants size field is tiny. what i should do ? above quering giving me all products but with empty variants
$result=$categories->with([
'products' => function ($product) {
return $product->with([
'variants' => function ($variants) {
return $variants->where('size','tiny');
}
]);
}
])->get();
CodePudding user response:
Change your code like this.
$result=$categories->with([
'products' => function ($product) {
return $product->whereHas(
'variants', function ($variants) {
return $variants->where('size','tiny');
}
]);
}
])->get();