您的 User 模型使用 Illuminate\Auth\Passwords\CanResetPassword 特征。该特征具有以下功能:
public function sendPasswordResetNotification($token)
{
// use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification
$this->notify(new ResetPasswordNotification($token));
}
当请求重置密码时,调用此方法并使用ResetPassword 通知发送电子邮件。
如果您想修改您的重置密码电子邮件,您可以创建一个新的自定义Notification 并在您的User 模型上定义sendPasswordResetNotification 方法以发送您的自定义Notification。直接在 User 上定义方法将优先于 trait 包含的方法。
创建一个扩展内置通知的通知:
use Illuminate\Auth\Notifications\ResetPassword;
class YourCustomResetPasswordNotification extends ResetPassword
{
/**
* Build the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('This is your custom text above the action button.')
->action('Reset Password', route('password.reset', $this->token))
->line('This is your custom text below the action button.');
}
}
在您的 User 上定义方法以使用您的自定义通知:
class User extends Authenticatable
{
public function sendPasswordResetNotification($token)
{
$this->notify(new YourCustomResetPasswordNotification($token));
}
}