For example, we have a model flight having 3 fields:
- created_at: the time when the flight created
- name: the name of the flight
- score: the score of the flight
So I write that:
$flights = App\Flight::orderBy('created_at');
I get some $flight
objects ordered by create_time
. So I will change the name of flight by create_time
to first_flight
, second_flight
and so on...
But I want to display $flights
sorted by score. So I have to sort $flights
by score, but I have no idea how to achieve that.
So my question is, how to sort Eloquent ORM objects by a field(in my example, it's score
)?