laravel-5.3 - Laravel 5.3 重新定义 "reset email" Blade 模板

标签 laravel-5.3

如何在 Laravel 5.3 中自定义重置电子邮件 Blade 模板的路径?

使用的模板是:vendor/laravel/framework/src/Illuminate/Notifications/resources/views/email.blade.php
我想建立自己的。

此外,如何更改此电子邮件中预定义的文本:vendor/laravel/framework/src/Illuminate/Auth/Notifications/ResetPassword.php

public function toMail()
{
    return (new MailMessage)
        ->line([
            'You are receiving this email because we received a password reset request for your account.',
            'Click the button below to reset your password:',
        ])
        ->action('Reset Password', url('password/reset', $this->token))
        ->line('If you did not request a password reset, no further action is required.');
}

最佳答案

要更改模板,您应该使用工匠命令 php artisan vendor:publish它将在您的 resources/views/vendor 中创建 Blade 模板目录。要更改电子邮件文本,您应该覆盖 User 模型上的 sendPasswordResetNotification 方法。这在此处进行了描述 https://laravel.com/docs/5.3/passwords重置电子邮件自定义 部分。

您必须将新方法添加到您的用户模型。

public function sendPasswordResetNotification($token)
{
    $this->notify(new ResetPasswordNotification($token));
}

并使用您自己的通知类而不是 ResetPasswordNotification。

更新 : 对于@lewis4u 请求

分步说明:
  • 要创建新的 Notification 类,您必须使用此命令行 php artisan make:notification MyResetPassword .它将在 app/Notifications 目录中创建一个新的通知类“MyResetPassword”。
  • 添加 use App\Notifications\MyResetPassword;到您的用户模型
  • 向您的用户模型添加新方法。
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new MyResetPassword($token));
    }
    
  • 运行 php artisan 命令 php artisan vendor:publish --tag=laravel-notifications运行此命令后,邮件通知模板将位于 resources/views/vendor/notifications 目录中。
  • 编辑您的 MyResetPassword类方法toMail()如果你想。这里有描述 https://laravel.com/docs/5.3/notifications
  • 如果您愿意,可以编辑您的电子邮件 Blade 模板。它是 resources/views/vendor/notifications/email.blade.php

  • 奖金: Laracast 视频:https://laracasts.com/series/whats-new-in-laravel-5-3/episodes/9

    PS:感谢@Garric15 关于php artisan make:notification 的建议

    关于laravel-5.3 - Laravel 5.3 重新定义 "reset email" Blade 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39327954/

    相关文章:

    redis - NOAUTH 需要身份验证。拉维尔+Redis

    mysql - 如何在 db raw laravel 中添加条件?

    php - 在循环 Laravel PHP 中捕获上一次迭代的值

    php - laravel 模型属性数组何时被填充?

    laravel - Laravel 5.3+ 中的 Route::controller() 替代方案

    php - 具有序列下一个值的 Eloquent 插入 id

    使用 Postman 的 Laravel 文件上传 API

    php - 拉维尔 5.3 : What is causing 'maximum execution time of 30 seconds exceeded'

    php - Laravel 身份验证在 Laravel 5.3 中无法正常工作