如何在 laravel 中查找未使用 Sentinel 登录的特定用户 ID 的角色名称和 ID

How find role name and id of a specific user id who is not logged in using Sentinel in laravel

如何在 Laravel 中找到未使用 Sentinel 登录的特定用户 ID 的角色名称和 ID?

// **** I have used this code =>
<?php Sentinel::getUser(4)->inRole('admin'); ?>

但这不起作用,因为 Sentinel::getUser() 仅适用于登录用户。 但是我需要在我的管理之一中找到未登录用户的角色名称和角色 ID,所以脚本应该是什么。我需要这方面的帮助。

您可以通过调用 $user = User::find(4) 根据他们的 ID 获取任何用户。然后使用哨兵你应该能够调用 $roles = $user->roles 这将 return 分配给该用户的所有角色或调用 $user->inRole('admin') 来检查他们是否处于特定角色。

编辑

为此,您需要在扩展基础 Sentinel EloquentUser class 的应用程序目录中设置用户模型 class。文件的顶部应如下所示:

<?php

namespace App;

use Cartalyst\Sentinel\Users\EloquentUser;
use Sentinel;

class User extends EloquentUser {

您好,我已经找到了解决我的问题的方法,它在视图页面中有效,下面给出了我使用的代码

<?php
    $user_id=3;
    $userR = App\User::find($user_id);
    $chk=$userR->inRole('admin');
    if($chk)
    {
        //***** logic comes here ******
    }
?>