通过散步到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)
);
}
不要忘记为新的通知添加到用户模型。