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

前端 未结 8 1440
孤独总比滥情好
孤独总比滥情好 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:24

    In Http->Middleware->Authenticate.php change login in else statement to /

    return redirect()->guest('/');
    

    and define following route in routes.php

    Route::get('/', function () {
        return view('login');
    });
    

    for logout call following function:

    public function getlogout(){
        \Auth::logout();
        return redirect('/home');
    }
    

    Important: redirect to /home instead of / that first calls $this->middleware('auth'); and then in middleware redirect to /

提交回复
热议问题