如何在 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 请求
分步说明:
php artisan make:notification MyResetPassword
.它将在 app/Notifications 目录中创建一个新的通知类“MyResetPassword”。 use App\Notifications\MyResetPassword;
到您的用户模型public function sendPasswordResetNotification($token)
{
$this->notify(new MyResetPassword($token));
}
php artisan vendor:publish --tag=laravel-notifications
运行此命令后,邮件通知模板将位于 resources/views/vendor/notifications 目录中。 MyResetPassword
类方法toMail()
如果你想。这里有描述 https://laravel.com/docs/5.3/notifications 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/