您如何在两个不同的ResetPasswordNotifications之间切换?
我已经获得了通常的重置密码,但是当管理员(在单独的控制器中)创建新用户时,他们也会获得重置密码"比如"通知。通过提供附加了生成和存储的标记的URL,它将具有不同的内容,但具有相同的目的。
我能看到如何做到这一点的唯一方法是:
然后在调用时,它会使用用户名param(原始)和一个额外的参数来切换通知,例如
密码:: broker() - > sendResetLink($ username,$ myNewToggleParam);
这是否是最简单的方法,并维护为用户创建和存储令牌的重置密码功能。
答案 0 :(得分:0)
通过向下走到PasswordBroker
找到解决方案,然后进入PasswordResetServiceProvider
以找出它在服务容器中实例化的位置,然后我就可以执行此操作另一个密码重置通知给用户,该用户刚刚由仪表板中的管理员创建。
为简洁起见,我只放入少量的公共端点,但为了完整性而添加它以防止解决方案在没有它的情况下丢失上下文:
/**
* Store a newly created user in storage, and send a notification to
* indicate the account was created and requires a password reset.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function store(Request $request)
{
$this->authorize('store', User::class);
$this->validate($request, [...]);
$user = $this->create($request);
$this->sendResetLinkEmail($user);
return response()->json([
'user' => $user,
'message' => trans('user.created'),
]);
}
/**
* Send a reset link to the new user.
*
* @param User $user
*/
private function sendResetLinkEmail(User $user)
{
// Reach into the service container for the password broker
$passwordBroker = App::make('auth.password.broker');
// Create a new token from the token repository, and send of the email
// notification to the new user to reset their password
$user->sendNewUserPasswordResetNotication(
$passwordBroker->getRepository()->create($user)
);
}
不要忘记将新通知添加到用户模型。