Dispatch a job from tinker in Laravel

Posted on

When you need to dispatch job from tinker, the normal command which is

AppJobsYourJob::dispatch();

would not work in tinker because dispatch helper function depends on garbage collection. Hence to dispatch a job from tinker, use any of the following commands

Bus::dispatch(new AppJobsYourJob($someArgument));
Enter fullscreen mode

Exit fullscreen mode

Queue::push(new AppJobsYourJob($someArgument)); 
Enter fullscreen mode

Exit fullscreen mode

Reference – https://github.com/laravel/tinker/commit/1baadfe1721f85cd4e776aa323128dcd329f170d#diff-04c6e90faac2675aa89e2176d2eec7d8

Leave a Reply

Your email address will not be published. Required fields are marked *