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.
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 yourQueueJob
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.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