Laravel 5.0 extends Exit functionality
I recently set up sessions to be saved to the database and added a user_id field to the sessions table so that I can display the names of logged in users. To get laravel to persist the user id on login (unless laravel is looking for a regular user_id column) I had to add some code to the Authenticate.php file to handle it.
Now I'm trying to set the user_id field to a value null
when the user logs out, because currently, since the user_id field still contains the user id even after logging out, it still displays them as done in the log, although they no longer logged in. I want to extend auth / logout functionality without affecting vendor files to enable my function to set user_id to null on logout.
Where can I add this feature exactly? In the AuthController.php file? Is my own auth / logout route declaration added in routes.php?
If you have any questions for me or if I need to explain something better, please let me know.
Thank.
source to share
You can put the following function in AuthController.php
to override the default function from AuthenticatesAndRegistersUsers
. And you can change it according to your needs.
/**
* Log the user out of the application.
*
* @return \Illuminate\Http\Response
*/
public function getLogout()
{
$this->auth->logout();
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}
source to share