我正在尝试通过语言环境获得热门帖子。下面的查询以某种方式可以工作,但只能得到一个结果。.在数据库中,还有四个测试记录。.另外,它还计算了错误的视图
$popularPostsByLocale = Post::select("post.id", "post.title", "post.slug",\DB::raw("SUM(views.views) as view_count"))
->join("views", function ($query) {
$query->on("views.viewable_id", "post.id")
->where([
["views.viewable_type", "App\Models\Post"],
["views.locale", \LaravelLocalization::setLocale()]
]);
})
->with("featured")
->where("post.status", "publish")
->orderBy("view_count","desc")
->take(5)
->get();
我在哪里出错以及如何解决?