laravel - Laravel 电子邮件验证模板位置
问题描述
我一直在阅读有关 laravel 电子邮件验证新功能的文档。在哪里可以找到发送给用户的电子邮件模板?它没有在这里显示:https ://laravel.com/docs/5.7/verification#after-verifying-emails
解决方案
Laravel 使用VerifyEmail通知类的这个方法来发送电子邮件:
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable);
}
return (new MailMessage)
->subject(Lang::getFromJson('Verify Email Address'))
->line(Lang::getFromJson('Please click the button below to verify your email address.'))
->action(
Lang::getFromJson('Verify Email Address'),
$this->verificationUrl($notifiable)
)
->line(Lang::getFromJson('If you did not create an account, no further action is required.'));
}
如果您想使用自己的电子邮件模板,您可以扩展基本通知类。
1) 在app/Notifications/
文件中创建VerifyEmail.php
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Lang;
use Illuminate\Auth\Notifications\VerifyEmail as VerifyEmailBase;
class VerifyEmail extends VerifyEmailBase
{
// use Queueable;
// change as you want
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable);
}
return (new MailMessage)
->subject(Lang::getFromJson('Verify Email Address'))
->line(Lang::getFromJson('Please click the button below to verify your email address.'))
->action(
Lang::getFromJson('Verify Email Address'),
$this->verificationUrl($notifiable)
)
->line(Lang::getFromJson('If you did not create an account, no further action is required.'));
}
}
2)添加到用户模型:
use App\Notifications\VerifyEmail;
和
/**
* Send the email verification notification.
*
* @return void
*/
public function sendEmailVerificationNotification()
{
$this->notify(new VerifyEmail); // my notification
}
此外,如果您需要刀片模板:
make:auth
当命令执行时,laravel 将生成所有必要的电子邮件验证视图。此视图放置在resources/views/auth/verify.blade.php
. 您可以根据应用程序的需要自由自定义此视图。
来源。
推荐阅读
- javascript - 如何在 process.stdin nodejs 上发出事件结束
- dafny - Dafny 断言语句是否具有效力?
- python - Python FFT:频移
- sql - ora-01821 日期格式无法识别
- javascript - 控制多个范围滑块 Django 表单
- python - 打印是 3 的幂的数字。我可以更好地编写这个程序吗?
- python - 我如何使用 tkinter 按钮导入文件
- python - 将 Python 与 SQL Server 连接起来
- cmake - 添加消毒剂仅用于调试 CMake 中的构建
- google-cloud-platform - 谷歌云平台 Kubernetes 的云位置(GKE)