framework: Job chaining does not allow constructor arguments on first job in chain
- Laravel Version: 5.5.12
- PHP Version: 7.1.8
- Database Driver & Version: MySQL (MariaDB 10.2.8)
Description:
When chaining queue jobs, the first job in the cain (the job where the chain is glued to) can not have any required constructor parameters.
Steps To Reproduce:
- Create a chain as mentioned in https://laravel.com/docs/5.5/queues#job-chaining
- Change the definition of the first in chain job (
ProcessPodcast
) to have a required paramter - Run the code
- Type error: Too few arguments to function App\Jobs\ProcessPodcast::__construct(), 0 passed in …
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (5 by maintainers)
You need to pass the required arguments to the dispatch method:
For those struggling, I managed to send differents constructor parameters like this:
Ran in to this problem myself. It’s by no means always practical to pass constructor arguments to dispatch(), as the withChain() method is specifically used to fire off a group of related jobs and they may well have entirely different constructors. Reinstantiating new objects as PendingChain currently does all with the same parameter set (and the same class) makes it substantially less useful as a feature.
Agreed. Ran into this issue today. This is very odd that every chained job is required to have the same parameters. Really limits this awesome feature.
https://laravel.com/docs/5.5/queues#dispatching-jobs