计数列表未更新
Count list not updating
我有一个列表,显示某项内容被评论了多少次问题是,当评论新内容时,该列表似乎没有更新。任何我如何改进它的想法,以便列表是实时的,我可以获得 20 个评论最多的结果。
到目前为止我有什么
表格:batsmen:id, name
评论: id, 标题, 评论, batsmen_id
控制器:
$batsmen = Batsmen::with('comments')->where('approved', '=', 1)->get()->take(25)->sortByDesc(function($commented)
{
return $commented->comments->count();
});
知道我是怎么做的,以便在每次评论后更新列表。
你能试试下面的代码吗?
$popularBatsmens = Batsmen::with('comments')
->withCount('comments')
->where('approved', '=', 1)
->orderBy('comments_count', 'DESC')
->take(20)
->get();
我有一个列表,显示某项内容被评论了多少次问题是,当评论新内容时,该列表似乎没有更新。任何我如何改进它的想法,以便列表是实时的,我可以获得 20 个评论最多的结果。
到目前为止我有什么
表格:batsmen:id, name 评论: id, 标题, 评论, batsmen_id
控制器:
$batsmen = Batsmen::with('comments')->where('approved', '=', 1)->get()->take(25)->sortByDesc(function($commented)
{
return $commented->comments->count();
});
知道我是怎么做的,以便在每次评论后更新列表。
你能试试下面的代码吗?
$popularBatsmens = Batsmen::with('comments')
->withCount('comments')
->where('approved', '=', 1)
->orderBy('comments_count', 'DESC')
->take(20)
->get();