通過散步到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)
);
}
不要忘記爲新的通知添加到用戶模型。