Laravel queue event not serializing models

↘锁芯ラ 提交于 2019-12-08 08:43:32

问题


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);
  }
}

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();

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.


回答1:


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

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.

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.

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




回答2:


for running queues you have to run php artisan queue:work

for this also make sure that driver is database you can set it your .env file.

Hope this helps



来源:https://stackoverflow.com/questions/48864247/laravel-queue-event-not-serializing-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!