In Laravel 5.3 I have a User model. I want to have the 10 users with the highest ranking on my server. The ranking is based on a sum of the columns Rank_a
, Rank_b
and Rank_c
. How can I do that?
This is the code I have so far:
$users = User::take(10)
->select(DB::raw('sum(Rank_a+Rank_b+Rank_c) AS total_points'))
->orderBy('total_points')
->get();
return response()->json($users);
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2h5GWRW
via IFTTT
Aucun commentaire:
Enregistrer un commentaire