【问题标题】:How to modify password change mail made with Laravel auth?如何修改使用 Laravel auth 制作的密码更改邮件?
【发布时间】:2017-09-12 11:17:13
【问题描述】:

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

当我请求重设密码时,我收到一封电子邮件,上面写着

(...)

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

(...)

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

注意here 是如何(仅)更改任何通知的一般外观,here 是如何更改(另外)通知的正文。 p>

非常感谢。

【问题讨论】:

标签: php laravel email frameworks passwords


【解决方案1】:

您的 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));
    }
}

【讨论】:

    【解决方案2】:

    首先打开一个终端并进入应用程序的根目录并运行以下命令:

    php artisan vendor:publish
    

    你会看到一些复制的文件,你可以在

    中找到电子邮件模板文件
    Root_Of_App/resources/views/vendor
    

    您可以在那里编辑通知的电子邮件模板。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-27
      • 2014-05-24
      • 2015-03-16
      • 2019-12-06
      • 2020-01-21
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      相关资源
      最近更新 更多