Logan Hasbrouck
Logan Hasbrouck

Reputation: 416

Laravel 5.0 extending the 'Logout' functionality

I recently set sessions to save to the database and added a user_id field to the sessions table so that I may display the names of logged in users. In order to get laravel to save the id of a user when they log in(given laravel doesn't look for a user_id column regularly), I had to add a bit of code to the Authenticate.php file to handle that.

Now, I am attempting to set the user_id field to null when the user logs out because presently, since the user_id field still contains the user's id even after they log out, it still displays them as logged in even though they are no longer logged in. I am looking to extend the auth/logout functionality without actually touching the vendor files to include my function to set the user_id to null on logout.

Where might I add this function to exactly? In the AuthController.php file? In routes.php adding in my own declaration of the auth/logout route?

If you have any questions for me or need me to better explain anything, let me know.

Thanks.

Upvotes: 3

Views: 1609

Answers (1)

pinkal vansia
pinkal vansia

Reputation: 10300

You can put following function in AuthController.php to override default function from AuthenticatesAndRegistersUsers trait. And you can change it as per your need.

/**
     * 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 : '/');
    }

Upvotes: 6

Related Questions