时间:2021-07-01 10:21:17 帮助过:33人阅读
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract
{
use Authenticatable, CanResetPassword, HasRoleAndPermission;
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
}
控制器:
public function index()
{
$user = \Auth::user();
$name=$user->name;
$role = $user->getRoles();
// return view('index', compact('name','role'));
dd($role);
}
dd()结果:
Collection {#370 ▼
#items: []
}
在laravel5.2中用roles这个包,想获得当前登录用户的role,得到一个空集合,为啥?
模型:
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract
{
use Authenticatable, CanResetPassword, HasRoleAndPermission;
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
}
控制器:
public function index()
{
$user = \Auth::user();
$name=$user->name;
$role = $user->getRoles();
// return view('index', compact('name','role'));
dd($role);
}
dd()结果:
Collection {#370 ▼
#items: []
}
如果没有addRoles默认就是空的啊……