Im trying to get a result from a database, what I want to do is get a sum of a curton field then group the results then order by. Heres what I have, but it keeps giving me an error. The error im getting is:
Call to a member function orderBy() on double in
Heres my code:
$app->place->where('week_no', $week)->where('win_lose', 'win')->groupBy('username')->sum('number')->orderBy('number', 'ASC')->get();
Any help is much appreciated. Thanks
Your error comes from the
sum()
call. It returns the sum of the elements, so other calls will simply fails cause you have a number and not an object anymore.I don't know your exact database schema, but I think that you can do what you want using: