How to Refresh the User object in Laravel

0 votes

In Laravel you can do this:

$user = Auth::user();

If I do changes on items on that object, it will give me what was there before my changes. How do I refresh the object to get the latest values? I.e. To force it to get the latest values from the DB?

Dec 2, 2020 in Laravel by kartik
• 37,490 points
52 views

1 answer to this question.

0 votes

Hello @kartik,

You can update the cache object like this.

Auth::setUser($user);

for Example

$user = User::find(Auth::user()->id);
$user->name = 'New Name';
$user->save();

Auth::setUser($user);

log::error(Auth::user()->name)); // Will be 'NEW Name'
answered Dec 2, 2020 by Niroj
• 82,680 points

Related Questions In Laravel

0 votes
1 answer

How to identify wheather the request is HTTP GET or HTTP POST in Laravel?

Hey, In order to identify the type of ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,680 points
261 views
0 votes
1 answer

How can we check the logged-in user info in Laravel?

Hey @kartik, yes we can keep track of ...READ MORE

answered Mar 20, 2020 in Laravel by Niroj
• 82,680 points
173 views
0 votes
1 answer

How to get the id when you're validating in the model Validation unique on update using laravel?

Hello @kartik, in Laravel's inbuilt auth system, the ...READ MORE

answered Sep 11, 2020 in Laravel by Niroj
• 82,680 points
1,699 views
0 votes
1 answer

How to set .env values in laravel programmatically on the fly?

Hello @kartik, Since Laravel uses config files to ...READ MORE

answered Sep 24, 2020 in Laravel by Niroj
• 82,680 points
893 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,680 points
6,697 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,680 points
780 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,680 points
583 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,680 points
7,119 views
0 votes
1 answer

How to “Refresh” the User object in Laravel?

Hello @kartik, You can update the cache object ...READ MORE

answered Sep 30, 2020 in Laravel by Niroj
• 82,680 points
335 views
0 votes
1 answer

How to get all the users except current logged in user in laravel eloquent?

Hello @kartik, You can get the current user's ...READ MORE

answered Dec 8, 2020 in Laravel by Niroj
• 82,680 points
490 views