How to logout and redirect to login page using Laravel 5.4?

前端 未结 11 1888
天命终不由人
天命终不由人 2020-12-23 08:58

I am using Laravel 5.4 and trying to implement authentication system. I used php artisan command make:auth to setup it. I edited the views according to my layout. Now, when

11条回答
  •  情深已故
    2020-12-23 09:52

    In your web.php (routes):

    add:

    Route::get('logout', '\App\Http\Controllers\Auth\LoginController@logout');
    

    In your LoginController.php

    add:

    public function logout(Request $request) {
      Auth::logout();
      return redirect('/login');
    }
    

    Also, in the top of LoginController.php, after namespace

    add:

    use Auth;
    

    Now, you are able to logout using yourdomain.com/logout URL or if you have created logout button, add href to /logout

提交回复
热议问题