如何修改使用 Laravel auth 制作的密码更改邮件?

emi*_*emi 1 php email passwords frameworks laravel

Laravel Framework 5.4.18 中,我刚刚跑了php artisan make:auth

当我请求重设密码时,我收到一封电子邮件,内容为

(……)

您收到这封电子邮件是因为我们收到了您帐户的密码重置请求

(……)

指定要说的文件在哪里?我想彻底改变它。

请注意,这里是如何变化(只)的任何通知的整体外观,而且这里是如何变化(除了)的通知的正文。

非常感谢。

pat*_*cus 5

您的User模型使用该Illuminate\Auth\Passwords\CanResetPassword特征。该特性具有以下功能:

public function sendPasswordResetNotification($token)
{
    // use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification
    $this->notify(new ResetPasswordNotification($token));
}
Run Code Online (Sandbox Code Playgroud)

当请求重置密码时,将调用此方法并使用ResetPassword通知发送电子邮件。

如果您想修改您的重置密码电子邮件,您可以创建一个新的自定义NotificationsendPasswordResetNotification在您的User模型上定义方法以发送您的自定义Notification. 直接在 上定义方法User将优先于特征包含的方法。

创建一个扩展内置通知的通知:

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.');
    }
}
Run Code Online (Sandbox Code Playgroud)

定义您User使用自定义通知的方法:

class User extends Authenticatable
{
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new YourCustomResetPasswordNotification($token));
    }
}
Run Code Online (Sandbox Code Playgroud)