Paul Diamant
Paul Diamant

Reputation: 189

Laravel order two columns from lower to higher

I have the following table structure; orders:

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

So to say I have 3 orders with the following data:

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

my goal is to fetch all orders and arrange them so the from_time and to_time are also in an ascending order, in my case the order would be 1, 3, 2.

Upvotes: 0

Views: 39

Answers (1)

Martin Bean
Martin Bean

Reputation: 39389

Use the orderBy() query method?

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

Upvotes: 2

Related Questions