Home > Mobile >  Session::flush is not working at first try in laravel
Session::flush is not working at first try in laravel

Time:04-06

I have this straightforward code that directly logouts the user but sometimes it doesnt clear the session. Note that this is on the service layer

public function logoutUser(): array
{
    Session::flush();
    Session::save();
    return [
        LoginConstants::BOOLEAN_RESULT => true,
        LoginConstants::APP_ID         => $this->oUtility->getAppId()
    ];
}

CodePudding user response:

Laravel own documentation suggest to do that:

/**
 * Log the user out of the application.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function logout(Request $request)
{
    Auth::logout();
 
    $request->session()->invalidate();
 
    $request->session()->regenerateToken();
 
    return redirect('/');
}

CodePudding user response:

If you want to logout then use ,

Auth::Logout();

Docs..

If You Want to Flush Session You can try ,

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

Read Documentation Here

  • Related