Reputation: 1373
I want to store some information of a user in session when he/she logs in to my application. And I want to destroy that session data after that user logs out of my application.
How can I achieve this in Laravel 5.4 with Auth?
Upvotes: 0
Views: 398
Reputation: 11906
Laravel calls authenticated
method after a successful login. You can add your session information here so that they get added when a user logs in.
Add this method to app/Http/Controllers/Auth/LoginController.php
protected function authenticated(Request $request, $user)
{
// Store information in session for user
}
By default laravel flushes all the session information when a user logs out. By if you want to handle it differently or make changes. Add this to your LoginController
and make the changes.
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->flush();
$request->session()->regenerate();
return redirect('/');
}
By doing the above you're basically overriding laravel's built in methods and adding additional functionality.
Upvotes: 1