我使用Laravel 5.4并使用内置身份验证参与了一个网站。
我添加了一个“忘记密码”链接,显示ResetPasswordController @ showLinkRequestForm,它在提交时通过电子邮件发送密码重置链接,然后ResetPasswordController @ showResetForm在提交时重定向到登录页面。
我遇到的问题是我们有两个不同的用户 - 客户端和管理员。我有能力确定哪个是通过注册的电子邮件地址,但我希望密码重置后的重定向对于每种类型(client ='/'和admin ='/ 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('/');
}
}
}
让我知道它是否对你有帮助:)