I have a command that runs a batch of jobs like this:
$batch = Bus::batch($jobs)
->then(function (Batch $batch) use ($reportId) {
$this->removeDuplicatedEmails();
$this->assignBonus($reportId);
})
->dispatch();
When I call the removeDuplicatedEmails and assignBonus functions inside ->then, I get this serialization error:
[2023-06-19 13:19:03] local.ERROR: Cannot assign Laravel\SerializableClosure\Serializers\Native to property Symfony\Component\Console\Input\InputArgument::$suggestedValues of type Closure|array {"exception":"[object] (TypeError(code: 0): Cannot assign Laravel\SerializableClosure\Serializers\Native to property Symfony\Component\Console\Input\InputArgument::$suggestedValues of type Closure|array at /var/www/html/vendor/laravel/serializable-closure/src/Serializers/Native.php:287)
However, if I put the code inside those functions directly into ->then, it works without any problems.
Additionally, when I execute the batch with these functions from inside a controller, it also works correctly.
Why am I getting this serialization error, and how can I fix it?