Laravel 5.7“邮件验证"如何排队电子邮件发送 [英] How to queue Laravel 5.7 "email verification" email sending
问题描述
Laravel 5.7 包含的电子邮件验证"功能运行良好,但异步电子邮件发送(在用户注册或重新发送链接页面期间)并不理想.
Laravel 5.7 included "email verification" feature works well but not async email sending (during user register or resend link page) is not ideal.
在 Laravel 5.7 中,有没有办法通过队列发送电子邮件验证电子邮件而无需重写整个电子邮件验证?
Is there any way to send the email verification email through a queue without rewrite whole email verification in Laravel 5.7 ?
推荐答案
没有内置的方法,但您可以通过扩展和覆盖轻松实现.
There is no built in way, but you can do it easily by extending and overriding.
首先,创建一个扩展内置通知的新通知,并实现 ShouldQueue 协定(以启用排队).以下类假设您在 app/Notifications/VerifyEmailQueued.php
处创建通知:
First, create a new notification that extends the built-in notification, and also implements the ShouldQueue contract (to enable queuing). The following class assumes you create a notification at app/Notifications/VerifyEmailQueued.php
:
namespace AppNotifications;
use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateAuthNotificationsVerifyEmail;
class VerifyEmailQueued extends VerifyEmail implements ShouldQueue
{
use Queueable;
// Nothing else needs to go here unless you want to customize
// the notification in any way.
}
现在您需要告诉框架使用您的自定义通知而不是默认通知.您可以通过覆盖 User
模型上的 sendEmailVerificationNotification()
来做到这一点.这只是改变了发送的通知.
Now you need to tell the framework to use your custom notification instead of the default one. You do this by overriding the sendEmailVerificationNotification()
on your User
model. This simply changes which notification gets sent out.
public function sendEmailVerificationNotification()
{
$this->notify(new AppNotificationsVerifyEmailQueued);
}
这篇关于Laravel 5.7“邮件验证"如何排队电子邮件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!