August 8th ʼ22 1 week ago
3 min 449 words
;1 suffix after the dispatch command:
If you want to dispatch a job into the queue through Laravel Artisan Tinker, you’ll open the Tinker and write:
And see the job is actually is not dispatched. If you run the command again, you’ll see the same response but the job is dispatched into the queue only once.
The problem is that Laravel Tinker keeps the generated
PendingDispatch objects in memory for the user to use in subsequent commands. When this object is destroyed, it actually dispatches the job.
To solve this job in the very right way, you can dispatch the job through Laravel’s
app(\Illuminate\Contracts\Bus\Dispatcher::class) ->dispatch(new SendEmailJob());
To solve this quickly and hacky:
By adding a
;1 suffix, Tinker will not keep
PendingDispatch objects in memory and dispatches jobs.