Reputation: 149
Check this code below:
$scores2 = Highscore::all()->orderBy('points', 'desc')->groupBy('user_id')->get();
I have this code, but when I load the page it won't get the highest score of each player. I don't know what I did wrong can somebody help me out please?
Upvotes: 2
Views: 221
Reputation: 4102
You need to remove ->all()
since you are receiving the data through the ->get()
method:
Highscore::orderBy('points', 'desc')->groupBy('user_id')->get();
The docs explains it really well.
Upvotes: 3
Reputation: 121
::all()
is static for ->get()
So if you want to make static method right after class use query()
like
$scores2 = Highscore::query()->orderBy('points', 'desc')->groupBy('user_id')->get();
and can format more pretty
$scores2 = Highscore::query()
->orderBy('points', 'desc')
->groupBy('user_id')
->get();
Upvotes: 0