Posts

Showing posts with the label jobs

Ways to Pass Parameters to Laravel job.

There are 2 ways to pass parameters to a dispatching job in Laravel. First is simply call dispatch() or dispatchNow() as per requirement on your Job class like calling a static method on a class: YourJob::dispatch(argument1, argument2, argument3); Second is simply pass arguments while creating an instance/object of Job class then pass the object to dispatch method(always available in the controller) like: $this->dispatchNow(new YourJob(argument1, argument2, argument3)); The arguments will be available in the constructor, can you assign them to class local variable properties and use anywhere in Job class. Let consider below example job: <?php namespace App\Jobs; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; class Testjob imple...