Gamer Gamer - 2 months ago 20
PHP Question

Laravel : Eloquent highest number in column

I have

users
table with
User
model, where every user have credit.

Suppose i have 3 users

User 1 have
500


User 2 have
300


User 3 have
200


How can i get all of these users for ranking, That user 1 have
500
credit, user 2 have
300
and user 3 have
200
!

I am not coming up with any logic .

Answer

You can use

$user=User::all();
$user->sortBy('columnName')->first():

This Could solve your problem