📜  laravel 统计用户类型 - PHP 代码示例

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

代码示例1
// laravel count the types of users
    $roles = Role::pluck('name');

    foreach ($roles as $roleName) {
        $userCount = User::whereHas('roles', function($query) use($roleName) {
            $query->where('name', $roleName);
        })->count();
    }