Laravel:OrderBy不工作?

I am trying to get all of the records in modal Roleplay order by the payslips_collected ASC (ascending).

Ascending is meant to start at the lowest value and go up. I am not getting that... here is my result of a table I made.

+----+------------------+--------+-------------+-----------------+-----------------+--------------+-----------+
| ID |    Username      | Shifts |  Completed  |  Registered     | Website Login   | Client Login | Last Seen |
+----+------------------+--------+-------------+-----------------+-----------------+--------------+-----------+
| 1  |  Danny Fure      |   29   | 1 year ago  |  43 minutes ago | 43 minutes ago  | 1 second ago |           |
| 2  |  James Mack      |   0    | 1 year ago  |  1 second ago   | 2 days ago      | 1 second ago |           |
| 3  |  Peter Barlow    |   0    | 1 year ago  |  1 second ago   | 2 days ago      | 1 second ago |           |
| 4  |  Adam Chapman    |   0    | 1 year ago  |  1 second ago   | 2 days ago      | 1 second ago |           |
| 5  |  Danny Burrows   |   0    | 1 year ago  |  1 second ago   | 2 days ago      | 1 second ago |           |
| 6  |  Kieran Root     |   0    | 1 year ago  |  1 second ago   | 2 days ago      | 1 second ago |           |
| 8  |  Ashton David    |   0    | 1 year ago  |  1 second ago   | 2 days ago      | 1 second ago |           |
| 9  |  Someone Special |   0    | 1 year ago  |  1 second ago   | 2 days ago      | 1 second ago |           |
| 10 |  Kelly Clark     |   0    | 1 year ago  |  1 second ago   | 2 days ago      | 1 second ago |           |
| 11 |  Abbie Grove     |   0    | 1 year ago  |  1 second ago   | 2 days ago      | 1 second ago |           |
+----+------------------+--------+-------------+-----------------+-----------------+--------------+-----------+

I'm sorry its a bit messed up, it didn't format correctly. But anyway, the main issue is its showing in DESC order, (descending) showing the highest before the lowest.

Can anyone tell me why its doing this?

Raw Query:

select * from `users` where exists (select * from `srp_user_statistics` where `users`.`id` = `srp_user_statistics`.`user_id` order by `payslips_collected` asc)

Code:

$players = Player::whereHas('roleplay', function ($query) use($orderType) {
    $query->orderBy('payslips_collected', $orderType);
});

Try this

$players = Player::has('roleplay')
    ->orderBy('payslips_collected', $orderType)
    // ...

I think you are getting like that as you are using order by for the sub-query not for the main select query so try to write order by out side you sub-query
Like this

$players = Player::whereHas('roleplay', function ($query) use($orderType) {
    $query->orderBy('payslips_collected', $orderType);
})->orderBy('id', $orderType);

Edit:-

select `users`.* from `users` join `srp_user_statistics` on `users`.`id` = `srp_user_statistics`.`user_id`
order by `srp_user_statistics.payslips_collected` asc

You can sort the results collection:

$sorted_players = $players->sortByDesc('payslips_collected');

Or simply reverse your actual results

$sorted_players = $players->reverse();

In some cases (I don't know when) Laravel will have its own default sort order come in front of your own...which obviously causes issues.

A trick to solve this is to reset any previous orders in the query with this line before you add your own:

$query->getQuery()->orders = null;

</div>