Getting rank of row in OrderBy desc Eloquent query, How can i make this query work in laravel 5.5 eloquents?)
问题 I am trying to give my users a ranking number for my Laravel hiscores pagination table. This is the MySQL query I found working. I am trying to put make this work as a Laravel eloquent query. select @i := @i + 1 ranking, t.* from (select @i:=0) initvars, users t ORDER BY wins DESC; My Laravel eloquent query right now: $ranking = User::orderBy('wins', 'DESC')->paginate(10); Thanks in advance! 回答1: A bit of a late response but I figured it out. This is my solution. I First added this function