Laravel 5.2: Auth::logout() is not working

前端 未结 8 1436
孤独总比滥情好
孤独总比滥情好 2020-12-16 00:04

I\'m building a very simple app in Laravel 5.2, but when using AuthController\'s action to log out, it just simply doesn\'t work. I have a nav bar which checks

相关标签:
8条回答
  • 2020-12-16 00:28
    /**
     * 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()->flush();
    
        $request->session()->regenerate();
    
        return redirect('/');
    }
    
    /**
     * Get the guard to be used during authentication.
     *
     * @return \Illuminate\Contracts\Auth\StatefulGuard
     */
    protected function guard()
    {
        return Auth::guard();
    }
    
    0 讨论(0)
  • 2020-12-16 00:30

    use below code

    Auth::logout();
    

    or

    auth()->logout();
    
    0 讨论(0)
提交回复
热议问题