我正在使用 Laravel 5.3 并自定义密码重置电子邮件模板。我已经完成了以下更改,以使用自定义 Mailable 类为通知创建自己的 html 电子邮件。这是我到目前为止的进展:
忘记密码控制器:
public function postEmail(Request $request)
{
$this->validate($request, ['email' => 'required|email']);
$response = Password::sendResetLink($request->only('email'), function (Message $message) {
$message->subject($this->getEmailSubject());
});
switch ($response) {
case Password::RESET_LINK_SENT:
return Response::json(['status' => trans($response)], 200);
case Password::INVALID_USER:
return Response::json(['email' => trans($response)], 400);
}
}
用户模型:
public function sendPasswordResetNotification($token)
{
Mail::queue(new ResetPassword($token));
}
ResetPassword 可邮寄类:
protected $token;
public function __construct($token)
{
$this->token = $token;
}
public function build()
{
$userEmail = 'something'; // How to add User Email??
$userName = 'Donald Trump'; // How to find out User's Name??
$subject = 'Password Reset';
return $this->view('emails.password')
->to($userEmail)
->subject($subject)
->with([
'token' => $this->token
'userEmail' => $userEmail,
'userName' => $userName
]);
}
如果您在上面注意到,我不确定如何传递用户名并找出用户的电子邮件地址。我需要从用户模型发送这些数据还是从 Mailable 类中查询它?有人可以告诉我我该怎么做吗?