Laravel Eloquent Joining Query (Multiple clauses of purpose in joining)
return TableA::leftJoin('table_b as b',function($join){
$join->on('b.foreign_id','=','table_a.id');
$join->where('b.status','=',1);
})
->where('table_a.group_name','emmet')
->groupBy('b.color')
->get([
'table_a.*'
DB::raw('SUM(b.price) as total_price')
]);
$join->on('b.foreign_id','=','table_a.id');
$join->where('b.status','=',1);
})
->where('table_a.group_name','emmet')
->groupBy('b.color')
->get([
'table_a.*'
DB::raw('SUM(b.price) as total_price')
]);
Comments
Post a Comment