Sorting data with Eloquent

后端 未结 5 642
傲寒
傲寒 2021-01-11 12:49

I\'m new to laravel (switched from CI) and eloquent ORM is still a bit of a mystery at some point!

Here is my problem :

I\'d like to sort data from my db usi

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-11 13:10

    Something like this could help.

    $content = Posts::with(array('comments' => function($query) {
                   $query->order_by('created_at', 'asc');
                }))
                ->get();
    

    Or if your problem is more complex:

    How to sort by a field of the pivot table of a many-to-many relationship in Eloquent ORM

提交回复
热议问题