📜  laravel 查询计数原始 - PHP 代码示例

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

代码示例2
DB::table('users')
    ->select('users.*', DB::raw('count(orders.user_id) as count_by_user_id'))
    ->join('orders' ,function($join){
        $join->on('orders.user_id', '=', 'users.id');
    })
    ->groupBy('users.id')
    ->orderBy('users.id', "DESC")
    ->get();