Laravel依关系排序

问题描述 投票:98回答:2

我正在浏览特定帖子的作者发表的所有评论。

foreach($post->user->comments as $comment)
    {
        echo "<li>" . $comment->title . " (" . $comment->post->id . ")</li>";
    }

这给了我

I love this post (3)
This is a comment (5)
This is the second Comment (3)

我将如何通过post_id进行排序,以使上面的列表按3,3,5的顺序排序

laravel laravel-4
2个回答
212
投票

可以通过查询功能扩展关系:


0
投票

我相信您也可以:

© www.soinside.com 2019 - 2024. All rights reserved.