与laravel 5.7一起提供的验证邮件 . 我需要改变它的方式和地点?我曾在网上搜索过,但由于它是5.7中的全新功能,所以我找不到答案 . 你能帮我吗?提前致谢 .
基本上该类在Illuminate \ Auth \ Notifications下
我想覆盖其中一个方法:
class VerifyEmail extends Notification
{
// i wish i could override this method
protected function verificationUrl($notifiable)
{
return URL::temporarySignedRoute('verification.verify', Carbon::now()->addMinutes(60), ['id' => $notifiable->getKey()]);
}
}
1 回答
因为
User
Model使用Illuminate\Auth\MustVerifyEmail
,所以可以覆盖方法sendEmailVerificationNotification,该方法通过调用方法notify
来通知创建的用户,并作为参数传递Notifications\MustVerifyEmail
类的新实例 .您可以在
User
模型的sendEmailVerificationNotification
方法中创建一个自定义通知,该通知将作为参数传递给$this->notify()
:在您的
CustomVerifyEmail
通知中,您可以定义route
,通过该处理将验证验证及其将采用的所有参数 .当新用户注册时,
App\Http\Controllers\Auth\RegisterController
中会发出Illuminate\Auth\Events\Registered
事件,并且该事件具有在App\Providers\EventServiceProvider
中注册的侦听器Illuminate\Auth\Listeners\SendEmailVerificationNotification
:此侦听器检查
$user
(在Laravel默认身份验证App\Http\Controllers\Auth\RegisterController
中作为参数传递给new Registered($user = $this->create($request->all()))
)是Illuminate\Contracts\Auth\MustVerifyEmail
的实例,这是Laravel建议在App\User
模型中使用的特征,当您要提供默认电子邮件验证和检查时还有$user
尚未经过验证 . 如果所有通过它将调用该用户的sendEmailVerificationNotification
方法: