Laravel 5.7 包含的“电子邮件验证”功能运行良好,但异步电子邮件发送(在用户注册或重新发送链接页面期间)并不理想。
有没有办法通过队列发送电子邮件验证电子邮件,而无需在 Laravel 5.7 中重写整个电子邮件验证?
没有内置的方法,但您可以通过扩展和覆盖轻松完成。
首先,创建一个新的通知来扩展内置通知,并实现 ShouldQueue 契约(以启用排队)。以下课程假设您在以下位置创建通知app/Notifications/VerifyEmailQueued.php
:
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Notifications\VerifyEmail;
class VerifyEmailQueued extends VerifyEmail implements ShouldQueue
{
use Queueable;
// Nothing else needs to go here unless you want to customize
// the notification in any way.
}
现在您需要告诉框架使用您的自定义通知而不是默认通知。您可以通过覆盖来做到这一点sendEmailVerificationNotification()
在你的User
模型。这只是改变发送的通知。
public function sendEmailVerificationNotification()
{
$this->notify(new \App\Notifications\VerifyEmailQueued);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)