Laravel 5.7 队列功能,但不发送电子邮件



>我已经使用 ShouldQueue 创建了一个通知,并且我的"作业"表被填充,但是当我启动命令:"php artisan queue:listen"时,表中的行被处理但不发送电子邮件。

如果不使用队列,所有代码函数和电子邮件都将发送到目的地。

我使用降价发送电子邮件。

命令:

namespace AppConsoleCommands;
use IlluminateConsoleCommand;
//
use Notification;
use AppNotificationsListiniNotifyListinoUpdate;
class StoreListinoOil extends Command
{
  /**
  * The name and signature of the console command.
  *
  * @var string
  */
  protected $signature = 'command:storelistinooil';
  /**
  * The console command description.
  *
  * @var string
  */

  /**
  * Create a new command instance.
  *
  * @return void
  */
  public function __construct()
  {
    parent::__construct();
  }
  /**
  * Execute the console command.
  *
  * @return mixed
  */
  public function handle()
  {
            $details = array(
              'day_listino' => 'today',
              'email' => 'email@email.com'
            );

            Notification::send($details, new NotifyListinoUpdate($details));

    dd('OK'); 
  }
}

通知 -> 通知列表更新

namespace AppNotificationsListini;
// use IlluminateBusQueueable;
use IlluminateNotificationsNotification;
// use IlluminateContractsQueueShouldQueue;
use IlluminateNotificationsMessagesMailMessage;
//
use IlluminateBusQueueable;
use IlluminateQueueSerializesModels;
use IlluminateQueueInteractsWithQueue;
use IlluminateContractsQueueShouldQueue;
use IlluminateFoundationBusDispatchable;
class NotifyListinoUpdate extends Notification implements ShouldQueue
{
    // use Queueable;
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    private $details;
    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($details)
    {
        $this->details = $details;
    }
    /**
     * 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 IlluminateNotificationsMessagesMailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
        ->subject('Notifica - '.$this->details['day_listino'])
        ->markdown('mail.admin.listino_update',['details'=> $this->details]);
    }
    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

您必须使用以下命令运行队列工作线程:

php artisan queue:work

查看以下文档:

运行队列工作线程

最新更新