📜  按视图数量降序排序 laravel - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:26.331000             🧑  作者: Mango

代码示例1
$posts = Post::select(DB::raw('posts.*, count(*) as `aggregate`'))
    ->join('views', 'posts.id', '=', 'views.post_id')
    ->groupBy('post_id')
    ->orderBy('aggregate', 'desc')
    ->get();