php - How to send parameters to queues? -
please consider following job:
<?php namespace app\jobs; use illuminate\contracts\bus\selfhandling; use illuminate\contracts\queue\shouldqueue; use illuminate\queue\interactswithqueue; use illuminate\queue\serializesmodels; class importusers extends job implements selfhandling, shouldqueue { use interactswithqueue, serializesmodels; public function __construct($number) { $this->number=$number; } public function handle() { dd($this->number); return; } }
dispatching job using sync
queue $this->dispatch(new \app\jobs\importusers(5));
throw exception: undefined property: app\jobs\importusers::$number
. seems odd me. why handle method can not access class properties?
properly declare property
class importusers extends job implements selfhandling, shouldqueue { use interactswithqueue, serializesmodels; protected $number; // <-- here public function __construct($number) { $this->number=$number; } public function handle() { dd($this->number); return; } }
what happens after jobs being deserialized queue loose dynamically created property.
try it:
$ php artisan tinker >>> bus::dispatch(new app\jobs\importusers(7)); 7 >>>
Comments
Post a Comment