使用自定义模板laravel 5.3替换密码重置邮件模板

编程入门 行业动态 更新时间:2024-10-27 16:31:16
本文介绍了使用自定义模板laravel 5.3替换密码重置邮件模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我执行了用于身份验证系统的laravel命令, php artisan make:auth 它为我的应用程序创建了身份验证系统,并且几乎所有东西都在工作.

I did the laravel command for authentication system , php artisan make:auth it made the authentication system for my app and almost everything is working.

现在,当我使用忘记的密码并且它向我的邮件id发送令牌时,我看到模板包含laravel和其他一些我想编辑或省略的内容,确切地说,我希望我的自定义模板能够在那里使用.

Now when i use the forgot password and it sends me a token to my mail id , i see that the template contains laravel and some other things that i might wanna edit or ommit, to be precise , i want my custom template to be used there.

我查看了控制器及其源文件,但是找不到在邮件中显示html的模板或代码.

I looked up at the controllers and their source files but i can't find the template or the code that is displaying the html in the mail.

我该怎么做?

我该如何更改?

这是从laravel到邮件的默认模板.

This is the default template that comes from laravel to the mail.

推荐答案

请注意:除了上一个答案之外,如果要修改 通知行 ,例如您正在接收此... 等.下面是分步指南.

Just a heads up: In addition to the previous answer, there are additional steps if you want to modify the notification lines like You are receiving this..., etc. Below is a step-by-step guide.

您需要覆盖默认值 sendPasswordResetNotification 您的 User 模型上的code>方法.

You'll need to override the default sendPasswordResetNotification method on your User model.

为什么?因为这些行是从 Illuminate \ Auth \ Notifications \ ResetPassword.php 中提取的.在核心中对其进行修改将意味着您的更改会在Laravel更新期间丢失.

Why? Because the lines are pulled from Illuminate\Auth\Notifications\ResetPassword.php. Modifying it in the core will mean your changes are lost during an update of Laravel.

为此,请将以下内容添加到您的 User 模型中.

To do this, add the following to your your User model.

use App\Notifications\PasswordReset; // Or the location that you store your notifications (this is default). /** * Send the password reset notification. * * @param string $token * @return void */ public function sendPasswordResetNotification($token) { $this->notify(new PasswordReset($token)); }

最后,创建该通知:

php artisan make:notification PasswordReset

此通知内容的示例:

/** * The password reset token. * * @var string */ public $token; /** * Create a new notification instance. * * @return void */ public function __construct($token) { $this->token = $token; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['mail']; } /** * Build the mail representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) { return (new MailMessage) ->line('You are receiving this email because we received a password reset request for your account.') // Here are the lines you can safely override ->action('Reset Password', url('password/reset', $this->token)) ->line('If you did not request a password reset, no further action is required.'); }

更多推荐

使用自定义模板laravel 5.3替换密码重置邮件模板

本文发布于:2023-11-16 04:43:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1601092.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   自定义   邮件   密码   laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!