{"id":"0cf19ebbd623362b","repo":"laravel/framework","slug":"session-store-requires-session-manager-to-be-avail","errorCode":null,"errorMessage":"Session store requires session manager to be available in container.","messagePattern":"Session store requires session manager to be available in container\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Cache/CacheManager.php","lineNumber":405,"sourceCode":"                $config['key'] ?? '_cache',\n            ),\n            $config\n        );\n    }\n\n    /**\n     * Get the session store implementation.\n     *\n     * @return \\Illuminate\\Contracts\\Session\\Session\n     *\n     * @throws \\InvalidArgumentException\n     */\n    protected function getSession()\n    {\n        $session = $this->app['session'] ?? null;\n\n        if (! $session) {\n            throw new InvalidArgumentException('Session store requires session manager to be available in container.');\n        }\n\n        return $session;\n    }\n\n    /**\n     * Create a new cache repository with the given implementation.\n     *\n     * @param  \\Illuminate\\Contracts\\Cache\\Store  $store\n     * @param  array  $config\n     * @return \\Illuminate\\Cache\\Repository\n     */\n    public function repository(Store $store, array $config = [])\n    {\n        return tap(new Repository($store, Arr::only($config, ['store'])), function ($repository) use ($config) {\n            if ($config['events'] ?? true) {\n                $this->setEventDispatcher($repository);\n            }","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Cache/CacheManager.php#L387-L423","documentation":"CacheManager::createSessionDriver() delegates to getSession(), which reads $this->app['session']. If the 'session' binding is absent (no session manager registered), it throws InvalidArgumentException. The session cache driver stores values in the user's HTTP session and therefore requires the session subsystem to be booted.","triggerScenarios":"Configuring a cache store with 'driver' => 'session' and resolving it from a context without the session manager bound: an artisan command, a queue worker, a unit test, or any non-HTTP entry point that does not boot SessionServiceProvider.","commonSituations":"Using 'session' as a cache driver and dispatching work to a queue worker. Running php artisan tinker or a scheduled task that resolves the cache. Removing SessionServiceProvider from a stateless API-only app while a store still references 'session'.","solutions":["Use a non-session cache driver (redis, database, file) for code paths that run outside HTTP requests (queues, commands).","Ensure Illuminate\\Session\\SessionServiceProvider is registered in config/app.php for HTTP-only usage.","If you genuinely need session-backed caching, only resolve that store inside a middleware-covered request lifecycle.","Switch CACHE_STORE to a durable driver and keep 'session' for request-scoped flash data only."],"exampleFix":"// before\n// config/cache.php uses 'session' driver; resolving in a queue worker:\nCache::store('session')->get('cart'); // throws\n\n// after\n// Use redis for cross-context caching:\nCache::store('redis')->get('cart');\n// keep session store only inside HTTP request middleware","handlingStrategy":"validation","validationCode":"if (app()->runningInConsole() && config('cache.stores.'.config('cache.default').'.driver') === 'session') {\n    throw new \\RuntimeException('Do not use the session cache driver in console/queue contexts.');\n}\nCache::get('k');","typeGuard":"function sessionDriverIsSafe(): bool\n{\n    return app()->bound('session')\n        && app()->make('request')->hasSession();\n}","tryCatchPattern":"try {\n    Cache::store('session')->get('k');\n} catch (\\InvalidArgumentException $e) {\n    if (str_contains($e->getMessage(), 'session manager')) {\n        return Cache::store('redis')->get('k');\n    }\n    throw $e;\n}","preventionTips":["Reserve the 'session' cache driver for HTTP-only code.","Use a durable driver for queues and commands.","Guard with app()->runningInConsole() before resolving session cache.","Document session cache limitations in project conventions."],"tags":["cache","session","configuration","ioc-container"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}