I get my Product be this code. I use with() method to load variations relation. I have some filters for it. But if any variations does't exist I get Product.
How can I get only this Product where variations exist ?
$query = Product::with(array(
'variations' => function($query) use($filters){
if(isset($filters['price_start']) && !empty($filters['price_start'])){
$query->groupBy('id')->having(DB::raw('SUM(price_base + price_engraving)'), '>=', $filters['price_start']);
}
if(isset($filters['price_end']) && !empty($filters['price_end'])){
$query->groupBy('id')->having(DB::raw('SUM(price_base + price_engraving)'), '<=', $filters['price_end']);
}
if(isset($filters['q_magazine_start']) && !empty($filters['q_magazine_start'])){
$query->where('q_magazine', '>', $filters['q_magazine_start']);
}
if(isset($filters['q_magazine_end']) && !empty($filters['q_magazine_end'])){
$query->where('q_magazine', '<', $filters['q_magazine_end']);
}
return $query;
}
))->whereIn('id', $productList);