Laravel 5.4 基于电子邮件地址的身份验证密码重置重定向

Laravel 5.4 Authentication password reset redirect based on email address

我参与了一个使用 Laravel 5.4 并使用内置身份验证的网站。

我添加了一个 "Forgot Password" link 来显示通过电子邮件发送密码的 ResetPasswordController@showLinkRequestForm 提交后重置 link,然后 ResetPasswordController@showResetForm 提交后重定向到登录页面。

我遇到的问题是我们有两个不同的用户 - 客户和管理员。我有能力确定哪个是 通过注册的电子邮件地址,但我希望重置密码后的重定向对于每种类型都不同 (客户端 = '/' 和管理员 = '/admin')。 这是怎么做到的?

如果您在控制器中使用 ResetsPasswords 特征,您可以创建自己的 redirectTo() 方法,该方法将被调用以重定向用户:

// import the needed trait
use Illuminate\Foundation\Auth\ResetsPasswords;

class YourResetPasswordController {
    // use the needed trait
    use ResetsPasswords;

    // override the method that redirects the user
    public function redirectTo()
    {
        if (auth()->user()->isAdmin()) {
            return redirect('/admin');
        } else {
            return redirect('/');
        }
    }
}

如果对您有帮助,请告诉我:)