Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

skihansen's avatar

Laravel 5 - What is the correct way to flush Session variables on logout?

In my app, I always want to flush the Session variables when a user logs out, but I'm not sure of the appropriate place to add this line of code.

0 likes
2 replies
MattCroft's avatar
Level 3

I've always used:

Session::flush();

And extending the AuthController's logout function like so

  /**
     * Log the user out of the application.
     *
     * @return \Illuminate\Http\Response
     */
    public function getLogout()
    {
        $this->auth->logout();

        Session::flush();

        return redirect('/');
    }
1 like
skihansen's avatar

Thanks! I'm new to Laravel, so I wasn't sure how to extend the logout function. Adding your code to AuthController.php along with:

use Session;

is all I needed.

Please or to participate in this conversation.