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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -