DEV Community

loading...

Dispatch a job from tinker in Laravel

jiteshdhamaniya profile image Jitesh Dhamaniya ・1 min read

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

App\Jobs\YourJob::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 App\Jobs\YourJob($someArgument));
Enter fullscreen mode Exit fullscreen mode
\Queue::push(new App\Jobs\YourJob($someArgument)); 
Enter fullscreen mode Exit fullscreen mode

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

Discussion (0)

pic
Editor guide