Laravel队列事件未序列化模型 [英] Laravel queue event not serializing models

查看:267
本文介绍了Laravel队列事件未序列化模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定我是否做错了什么,但是尝试广播事件时,SerializesModels仅序列化我抛出的第一个模型.

Not sure if i did something wrong, but when attempting do broadcast an event, the SerializesModels only serializes the first model I throw at it.

class WorkerQueueEvent implements ShouldBroadcast
{
  use Dispatchable, InteractsWithSockets, SerializesModels;

  protected $user;
  public $queue;
  public function __construct(User $user,QueueJob $queue)
  {
    $this->user = $user;
    $this->queue = $queue;
  }
  public function broadcastOn()
  {    
    return new PrivateChannel('Queues/' . $this->user->id);
  }
}

这导致队列从未被处理过. 如果我在构造器中执行dd($queue);dd($user);,它会记录两个日志,但它永远不会到达broadcastOn();.

This results in the queue never being processed. If i do an dd($queue); or dd($user); in the constructer, it does log both of them, but it never reaches broadcastOn();

我确实做到了这一点,传递了QueueJob id并在广播函数中获取了它,只是问我是在做错什么还是实际上是个错误.

I did got it to work, passing QueueJob id and fetching it on the broadcast function, just asking if i was doing something wrong or if this is in fact an error.

推荐答案

我相信这里的问题是您的public $queue属性.

I believe the issue here is your public $queue property.

文档指出,您可以通过定义事件队列来指定事件队列$broadcastQueue属性.但是,没有提到如果未定义$broadcastQueue,它还会检查$queue属性.

The documentation states that you can specify an event queue by defining the $broadcastQueue property. However, it doesn't mention that it also checks for the $queue property if $broadcastQueue is not defined.

由于定义了$queue属性,它将尝试将事件推送到以QueueJob模型实例的__toString()值命名的队列中,我假设该事件不存在,以及为什么您的作业永远不会发送到队列.

Since you have defined a $queue property, it will attempt to push your event onto the queue named by the __toString() value of your QueueJob model instance, which I'm assuming doesn't exist and why your job is never sent to a queue.

如果将属性重命名为类似$queueJob的名称,那么我认为它应该对您有用.

If you rename your property to something like $queueJob, then I believe it should work for you.

这篇关于Laravel队列事件未序列化模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆