How to change the redirect url when logging out?

后端 未结 8 2040
没有蜡笔的小新
没有蜡笔的小新 2020-12-16 16:08

I\'m working with Laravel 5 authentification system provided by default. After logging out, a user is redirected to the root page but I\'d like to change that. I managed to

相关标签:
8条回答
  • 2020-12-16 16:43

    I have a same problem in Laravel 5.0. Override a method does the trick.

    1) Go to app/Http/Controllers/Auth/AuthController.php 2) Add a new method :

    // Override Logout method (define custom url)
    public function getLogout()
    {
        $this->auth->logout();
        return redirect('auth/login');  // Your Custom URL
    }
    
    0 讨论(0)
  • 2020-12-16 16:51

    If you don't provide the $redirectAfterLogout attribute, it will use the default which is '/'.

    This logic can be found in this class: \vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php

    public function logout()
    {
        Auth::guard($this->getGuard())->logout();
    
        return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
    }
    

    Having said that, just add this attribute in your AuthController:

    protected $redirectAfterLogout = '/afterRedirectURL';
    
    0 讨论(0)
提交回复
热议问题