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

HarshaReddy's avatar

prevent going back after logout (based on session)

I don't want to go back after sessions destroyed. If we try to go back,it should come to login page again! Hope i will get best answer!

0 likes
7 replies
ahmeddabak's avatar

In your App\Http\Controllers\Auth\LoginController you can override the logout method to prevent redirecting back, here you can send the user where ever you want

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

        $request->session()->invalidate();

        return $this->loggedOut($request) ?: redirect('/login'); //redirect to login
    }
1 like
HarshaReddy's avatar

@ahmeddabak i need jobseeker and employer logout functionalities! But as you said in LoginController i did not find any logout() function

ahmeddabak's avatar

The method is there, but it is hidden in a trait.

Just add the code i gave you to the LoginController

HarshaReddy's avatar

up to logout it is working fine,but after logout it is coming to dashboard page,when we click back button in browser. Is this we restrict in view page?

ahmeddabak's avatar

That is not a problem, it is only a cached version of the page in the browser. The user will be logged out and will not be able to do anything

ahmeddabak's avatar

If the problem is solved, please mark this as solved

Please or to participate in this conversation.