I have the next problem: After auth user with Auth Passport provider in Laravel I get Auth::user()
. Then I try to append variable to it.
$role = Input::get('role');
$user = Auth::user();
$user->role = $role;
Auth::setUser($user);`
It works well if use a new $user
variable in current controller and route, but if I try to get Auth::user()
in another route it returns old values. How to append variable to Auth::user()
and then save it and cache it? I want to change Auth::user()
with "setUser" method and then cache it for use on all other routes. How can I solve my problem?
The reason why Auth::user()
its returning you the old value on other places is that Auth::user()
is an authentication system that takes user credentails validates and then compare them agains the User model
(aka default laravel auth)
With setUser
you are just setting some properties when you new up the instance thats why in other places u get the old value which is being pulled from User model
as in different places the setUser
its unset.
You can use append on User model for this,
for example,
protected $appends = [ 'my_role' => 1];