国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

使用 Eloquent 查詢將使用者分組(總使用者、管理員使用者、控制操作員、警衛(wèi))
P粉026665919
P粉026665919 2024-04-05 12:11:26
0
1
706

我有一個(gè)查詢,其中計(jì)算所有用戶,具有角色「admin」的用戶總數(shù)具有角色「control_operator」的用戶總數(shù)和具有角色「guard」的使用者總數(shù)。

查詢正在工作,但有一個(gè)我無法弄清楚的小故障/錯(cuò)誤。

資料庫中實(shí)際上有 2 個(gè)用戶,其中一個(gè)具有 super_admin 和 admin 角色,另一個(gè)具有 control_operator。前端顯示的是這樣的:

為什麼只有 2 個(gè)使用者時(shí)卻有 3 個(gè)使用者?

這是我的查詢

// Retrieve the counts of admins, users, control operators, and security guards
        $countData = User::selectRaw('
        SUM(CASE WHEN roles.name = "admin" THEN 1 ELSE 0 END) as totalAdmins,
        COUNT(*) as totalUsers,
        SUM(CASE WHEN roles.name = "control_operator" THEN 1 ELSE 0 END) as totalControl,
        SUM(CASE WHEN roles.name = "security_guard" THEN 1 ELSE 0 END) as totalGuards
    ')->join('model_has_roles', 'users.id', '=', 'model_has_roles.model_id')
      ->join('roles', 'model_has_roles.role_id', '=', 'roles.id')
      ->first();

P粉026665919
P粉026665919

全部回覆(1)
P粉111227898

雷雷

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板