简体   繁体   中英

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

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

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

But this doesn't work as Sentinel::getUser() works only for logged in user. But I need to find role name and role id of nonlogged user in one of my managament , so what should be the script. I need help on this.

You can get any user based on their id by calling $user = User::find(4) . Then with sentinel you should be able to call $roles = $user->roles which will return all the roles that are assigned to that user or call $user->inRole('admin') to check if they're in a specific role.

EDIT

For this to work you will need to have a User model class set up in the app directory that extends the base Sentinel EloquentUser class. The top of the file should look something like this:

<?php

namespace App;

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

class User extends EloquentUser {

Hi I have got a solution to my problem , and its working in the view page , the code that i have used is given below

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM