Laravel Eloquent builder – combining groupBy and orderBy

Solution:

I’ll just put this here. For reference purposes.

return self::select(DB::raw('item,sum(quantity_purchased) as total_quantity_purchase'))
        ->where('isRefundedCompletely',false)
        ->groupBy('item_id')
        ->orderBy('quantity_purchase','DESC')
        ->get();