Laravel订购从低到高的两列

时间:2018-05-16 11:18:43

标签: laravel

我有以下表格结构; 订单:

 id, user_id, from_time, to_time, product_id, quantity, price, created_at, updated_at

所以说我有3个订单,包含以下数据:

user_id: 1,
from_time: 10:00,
to_time: 11:00

user_id: 2,
from_time: 12:00,
to_time: 15:00

user_id: 3,
from_time: 11:00,
to_time: 12:00

我的目标是获取所有订单并对其进行排列,以便from_timeto_time也在ascending order中,在我的情况下,订单将为1, 3, 2.

1 个答案:

答案 0 :(得分:2)

使用orderBy()查询方法?

Foo::orderBy('from_time', 'asc')->orderBy('to_time', 'asc');