Skip to content
Advertisement

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.

JavaScript

My Laravel eloquent query right now:

JavaScript

Advertisement

Answer

This is my solution.

I first added this function to my User Modal Class.

JavaScript

Now in my view I run my getRanking() function.

JavaScript

I am using my array keys to determine the user ranking.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement