【问题标题】:Reset Password Email重设密码电子邮件
【发布时间】:2017-08-30 06:41:20
【问题描述】:
我是 laravel 开发的新手,目前正在做一个小项目。我想为重置密码自定义电子邮件模板,甚至将其链接到完全不同的模板。对于身份验证脚手架,我使用了 php artisan make:auth 命令。
但是默认的重置密码功能使用默认的 laravel 电子邮件模板。我是否可以创建不同的电子邮件模板并将其链接到重置密码控制器?另外我想传入额外的用户信息。
我使用的是 laravel 5.4 版本。
【问题讨论】:
标签:
php
laravel
email
frameworks
blade
【解决方案1】:
您可以使用以下命令生成通知类:
php artisan make:notification ResetPassword
您可以在那里重写toMail() 方法来自定义主题和行。
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Reset Password Request')
->line('You are receiving this email because we received a password reset request for your account.')
->action('Reset Password', url('password/reset', $this->token))
->line('If you did not request a password reset, no further action is required.');
}
在users 模型中:
use Illuminate\Notifications\Notifiable;
use App\Notifications\ResetPassword as ResetPasswordNotification;
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
并自定义整个电子邮件模板。这是视图:resources/views/notification/email.blade.php;
而在config/app.php,你可以更改应用名称,默认是laravel。