Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question