D
D
Dmitriy2020-09-29 12:46:46
Laravel
Dmitriy, 2020-09-29 12:46:46

How to sort model by Laravel relationships?

There are models Order, OrderItem, Platform.
Order hasMany OrderItems.
OrderItem belongsTo Platform.
OrderItem belongsToOrder .
I need to sort Platform by the passed values ​​sorting, direction .
How to do it?
OrderItem:
id
order_id
platform_id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Grechushnikov, 2020-10-06
@maxyc_webber

https://laravel.com/docs/8.x/eloquent-relationship...
$users = App\Models\User::with(['posts' => function ($query) {
$query->orderBy( 'created_at', 'desc');
}])->get();
https://stackoverflow.com/questions/28634921/larav...
https://laravel.demiart.ru/ordering-by-relationshi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question