首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Laravel更改激活电子邮件和队列

Laravel更改激活电子邮件和队列
EN

Stack Overflow用户
提问于 2016-11-24 10:42:49
回答 1查看 258关注 0票数 0

我已覆盖激活通知,但我在发送电子邮件时遇到一些问题。它在不使用队列时工作,否则它停留在数据库队列中,我不知道如何修复它。然而,我知道队列的工作方式与使用数据库队列发送电子邮件一样有效。

所以这不起作用:

代码语言:javascript
运行
复制
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class SendActivationEmail extends Notification implements ShouldQueue
{
    use Queueable;

    protected $token;

    /**
     * Create a new notification instance.
     *
     * SendActivationEmail constructor.
     * @param $token
     */
    public function __construct($token)
    {
        $this->token = $token;
        $this->onQueue('social');
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('Activation email')
            ->greeting('xxx - Hello!')
            ->line('You need to activate your email before you can start using all of our services.')
            ->action('Activate Email', route('authenticated.activate', ['token' => $this->token]))
            ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

但这项工作:

代码语言:javascript
运行
复制
<?php

namespace App\Notifications;

use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class SendActivationEmail extends Notification
{

    protected $token;

    /**
     * Create a new notification instance.
     *
     * SendActivationEmail constructor.
     * @param $token
     */
    public function __construct($token)
    {
        $this->token = $token;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('Activation email')
            ->greeting('xxx - Hello!')
            ->line('You need to activate your email before you can start using all of our services.')
            ->action('Activate Email', route('authenticated.activate', ['token' => $this->token]))
            ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

类似这样的东西也可以工作:

代码语言:javascript
运行
复制
Mail::to($user->email)
            ->queue(new Welcome($user));

在我的数据库队列中:(尝试次数不断增加)

代码语言:javascript
运行
复制
{"job":"Illuminate\\Queue\\CallQueuedHandler@call","data":{"commandName":"Illuminate\\Notifications\\SendQueuedNotifications","command":"O:48:\"Illuminate\\Notifications\\SendQueuedNotifications\":6:{s:14:\"\u0000*\u0000notifiables\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":2:{s:5:\"class\";s:15:\"App\\Models\\User\";s:2:\"id\";a:1:{i:0;i:12;}}s:15:\"\u0000*\u0000notification\";O:43:\"App\\Notifications\\SendActivationEmail\":5:{s:8:\"\u0000*\u0000token\";s:64:\"f594ec1d2c15bf5c51903b1b408100b6de449895a042ddbe701d014b46a2bd8c\";s:2:\"id\";s:36:\"20d8a21a-3a69-47cf-a37d-bc98f2a83600\";s:10:\"connection\";N;s:5:\"queue\";s:7:\"default\";s:5:\"delay\";N;}s:11:\"\u0000*\u0000channels\";a:1:{i:0;s:4:\"mail\";}s:10:\"connection\";N;s:5:\"queue\";s:7:\"default\";s:5:\"delay\";N;}"}}

有什么想法吗?

EN

Stack Overflow用户

发布于 2016-11-24 10:49:07

我忘记创建一个表通知,也不知道它是必需的。

只需要执行以下两个命令行:

代码语言:javascript
运行
复制
php artisan notifications:table
php artisan migrate
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40777271

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档