[英]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
,它將返回分配給該用戶的所有角色,或者調用$user->inRole('admin')
來檢查它們是否在特定角色中角色。
編輯
為此,您需要在app目錄中設置一個User模型類,以擴展Sentinel EloquentUser基類。 文件頂部應如下所示:
<?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 ******
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.