{"id":"bdd41637b27643bb","repo":"laravel/framework","slug":"to-enable-support-for-closure-jobs-please-install","errorCode":null,"errorMessage":"To enable support for closure jobs, please install the illuminate/queue package.","messagePattern":"To enable support for closure jobs, please install the illuminate/queue package\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Bus/Queueable.php","lineNumber":321,"sourceCode":"            $this->chained = array_merge($this->chained, [$this->serializeJob($job)]);\n        }\n\n        return $this;\n    }\n\n    /**\n     * Serialize a job for queuing.\n     *\n     * @param  mixed  $job\n     * @return string\n     *\n     * @throws \\RuntimeException\n     */\n    protected function serializeJob($job)\n    {\n        if ($job instanceof Closure) {\n            if (! class_exists(CallQueuedClosure::class)) {\n                throw new RuntimeException(\n                    'To enable support for closure jobs, please install the illuminate/queue package.'\n                );\n            }\n\n            $job = CallQueuedClosure::create($job);\n        }\n\n        return serialize($job);\n    }\n\n    /**\n     * Dispatch the next job on the chain.\n     *\n     * @return void\n     */\n    public function dispatchNextJobInChain()\n    {\n        if (is_array($this->chained) && ! empty($this->chained)) {","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Bus/Queueable.php#L303-L339","documentation":"Queueable::serializeJob() wraps a Closure into CallQueuedClosure before serializing it into a job chain. If the Illuminate\\Queue\\CallQueuedClosure class does not exist (the illuminate/queue package is not installed), it throws a RuntimeException telling the user to install it. Closure chaining requires the queue subsystem.","triggerScenarios":"Calling $job->chain([function () { ... }]) or appendToChain(function () {...}) in an installation that has illuminate/bus but not illuminate/queue. Serializing a closure-based job via the Queueable trait without the queue package present.","commonSituations":"Using illuminate/bus or illuminate/pipeline standalone packages and trying to chain closures. A partial composer require that pulled bus but not queue. Refactoring a monolith into a slim worker that omits illuminate/queue.","solutions":["Run 'composer require illuminate/queue' to provide CallQueuedClosure and the queue runtime.","Alternatively, replace the closure with a concrete job class so no CallQueuedClosure wrapping is needed.","If closures must be used, also install laravel/serializable-closure (a dependency used by CallQueuedClosure)."],"exampleFix":"// before\n$job->chain([\n    function () { logger('done'); },\n]);\n\n// after (option A: install package)\n// composer require illuminate/queue\n\n// after (option B: use a class)\nclass LogDoneJob implements ShouldQueue {\n    use Queueable;\n    public function handle() { logger('done'); }\n}\n$job->chain([new LogDoneJob()]);","handlingStrategy":"validation","validationCode":"if (! class_exists(\\Illuminate\\Queue\\CallQueuedClosure::class)) {\n    throw new \\RuntimeException('Install illuminate/queue to chain closure jobs.');\n}\n$job->chain([$closureJob]);","typeGuard":"function closureJobsAreSupported(): bool\n{\n    return class_exists(\\Illuminate\\Queue\\CallQueuedClosure::class)\n        && class_exists(\\Laravel\\SerializableClosure\\SerializableClosure::class);\n}","tryCatchPattern":"try {\n    $job->chain([fn () => doWork()]);\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'illuminate/queue')) {\n        // run composer require illuminate/queue then retry\n    }\n    throw $e;\n}","preventionTips":["Prefer concrete job classes over closures for testability.","Pin illuminate/queue in composer.json when using illuminate/bus.","Document package dependencies for closure-based jobs."],"tags":["bus","queue","closures","configuration"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}