我正在遍历特定帖子的作者发布的所有评论。
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
原文由 PrestonDocks 发布,翻译遵循 CC BY-SA 4.0 许可协议
可以使用查询函数扩展关系:
[评论后编辑]
默认用户模型 + 简单控制器示例;获取评论列表时,只需根据 Input::get() 应用 orderBy()。 (一定要进行一些输入检查;))