In laravel5.2 with roles this package, want to get the current login user role, get an empty collection, why?
Model:
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract{ use Authenticatable, CanResetPassword, HasRoleAndPermission; protected $fillable = [ 'name', 'email', 'password', ]; protected $hidden = [ 'password', 'remember_token', ];}
Controller:
public function index() { $user = \Auth::user(); $name=$user->name; $role = $user->getRoles(); // return view('index', compact('name','role')); dd($role); }
DD () Results:
Collection {#370 ▼ #items: []}
Reply content:
In laravel5.2 with roles this package, want to get the current login user role, get an empty collection, why?
Model:
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract{ use Authenticatable, CanResetPassword, HasRoleAndPermission; protected $fillable = [ 'name', 'email', 'password', ]; protected $hidden = [ 'password', 'remember_token', ];}
Controller:
public function index() { $user = \Auth::user(); $name=$user->name; $role = $user->getRoles(); // return view('index', compact('name','role')); dd($role); }
DD () Results:
Collection {#370 ▼ #items: []}
If not addroles the default is empty ah ...