我的密码在这里。我只想根据最新发布的评论对其进行分类。
$comments = ModelsComment::with('Comments')->where('posts_id', $this->post)
->WhereHas('Comments', function ($q){
$q->orderBy('created_at', 'DESC'); //->latest()
})->paginate('5');ModelsComment是我的枢轴表(这里没有时间戳),所以我尝试根据最新添加的评论(相关表)对其进行排序。
然而,最古老的记录仍然出现在顶部。任何帮助都将不胜感激。
我的表结构是这样的
POST
id
name
timestamps
ModelsComment(without timestamps)
posts_id
comments_id
Comments
id
name
timestamps我正在尝试从我的ModelsComment中查询,并首先用最新的/最新的条目来订购注释表。
发布于 2022-03-12 05:40:48
使用此版本:
$comments = ModelsComment::with(['Comments' => function ($q) {
$q->orderBy('created_at', 'DESC')
}])
->paginate('5')
->get();https://stackoverflow.com/questions/71447170
复制相似问题