duanhuren5581 2017-08-02 11:06
浏览 99

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);
});
  • 写回答

4条回答 默认 最新

  • douxu3732 2017-08-02 11:11
    关注

    Try this

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

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来