I am having trouble implementing the group_by and having queries using Eloquent in Laravel.
Here is the scenario:
orders
- id
- qty
deliveries
-
Ended up switching to Laravel 4 and doing the ff which seemed to work.
Order::leftJoin('deliveries', 'orders.id', '=', 'deliveries.order_id')
->select(array('orders.*'), DB::raw('orders.qty - IFNULL(sum(deliveries.qty),0) AS balance')))
->groupBy('order_id')
->havingRaw('balance > 0')
->get();