Reputation: 253
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.
Upvotes: 1
Views: 1984
Reputation: 253
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 ******
}
?>
Upvotes: 0
Reputation: 429
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 {
Upvotes: 0