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

anas_repo's avatar

Laravel sanctum SPA on logout not set user_id field null

I use Laravel sanctum SPA specifically through sessions and cookies when logging out the user_id field in Database is not set to null after the user logs out, but it remains until another request comes with the same session and same SANCTUM_STATEFUL_DOMAINS in Origin Header and then it becomes null

I use sessions in the database

I use Laravel API Routes

logout :

    public function logout(Request $request)
    {
     
        Auth::guard('web')->logout();
        $request->session()->invalidate();
        $request->session()->regenerateToken();

        return ['msg' => "ok"];
    }
0 likes
1 reply
vincent15000's avatar

You should Sanctum SPA authentication with Fortify to login / logout, I never had any problem doing so.

Please or to participate in this conversation.