Laravel 6.0 - 自定义电子邮件验证:temporarySignedRoute() URL 不适用于新路由
Laravel 6.0 - Custom email verification: temporarySignedRoute() URL not working with new route
我正在尝试从 5.8 升级到 Laravel 6。我们使用带有以下代码的自定义验证电子邮件 Notification
来获取验证 URL:
URL::temporarySignedRoute(
'verification.verify',
Carbon::now()->addMinutes(60),
[
'id' => $notifiable->getKey(),
]
);
这似乎生成了一个不适用于新路由 (check this) 的 URL,例如:
http://host/email/verify/38?expires=1574602925&signature=4410c2230623619633be56d3641814cea3c77236bf8435cba88fc102a35d3dc4
到目前为止,我无法在网上找到关于该特定主题的任何内容,所以如果您能帮助我在 Laravel 6 中使用它,我将不胜感激。
提前致谢。
好的,我在以下位置找到了解决方案:
vendor/laravel/framework/src/Illuminate/Auth/Notifications/VerifyEmail.php
必须将代码更改为:
return URL::temporarySignedRoute(
'verification.verify',
Carbon::now()->addMinutes(60),
[
'id' => $notifiable->getKey(),
'hash' => sha1($notifiable->getEmailForVerification()),
]
);
你可以插入AppServiceProvider->boot:
public function boot()
{
VerifyEmail::toMailUsing(function ($notifiable) {
$verifyUrl = URL::temporarySignedRoute(
'verification.verify', Carbon::now()->addMinutes(60),
[
'id' => $notifiable->getKey(),
'hash' => sha1($notifiable->getEmailForVerification()),
]
);
return (new MailMessage)->subject('Welcome!')->markdown('emails.verify', ['url' => $verifyUrl]);
});
}
查看电子邮件模板在 views/emails/verify。blade.php
我正在尝试从 5.8 升级到 Laravel 6。我们使用带有以下代码的自定义验证电子邮件 Notification
来获取验证 URL:
URL::temporarySignedRoute(
'verification.verify',
Carbon::now()->addMinutes(60),
[
'id' => $notifiable->getKey(),
]
);
这似乎生成了一个不适用于新路由 (check this) 的 URL,例如:
http://host/email/verify/38?expires=1574602925&signature=4410c2230623619633be56d3641814cea3c77236bf8435cba88fc102a35d3dc4
到目前为止,我无法在网上找到关于该特定主题的任何内容,所以如果您能帮助我在 Laravel 6 中使用它,我将不胜感激。
提前致谢。
好的,我在以下位置找到了解决方案:
vendor/laravel/framework/src/Illuminate/Auth/Notifications/VerifyEmail.php
必须将代码更改为:
return URL::temporarySignedRoute(
'verification.verify',
Carbon::now()->addMinutes(60),
[
'id' => $notifiable->getKey(),
'hash' => sha1($notifiable->getEmailForVerification()),
]
);
你可以插入AppServiceProvider->boot:
public function boot()
{
VerifyEmail::toMailUsing(function ($notifiable) {
$verifyUrl = URL::temporarySignedRoute(
'verification.verify', Carbon::now()->addMinutes(60),
[
'id' => $notifiable->getKey(),
'hash' => sha1($notifiable->getEmailForVerification()),
]
);
return (new MailMessage)->subject('Welcome!')->markdown('emails.verify', ['url' => $verifyUrl]);
});
}
查看电子邮件模板在 views/emails/verify。blade.php