laravel/framework · error · InvalidArgumentException

Session store requires session manager to be available in co

Error message

Session store requires session manager to be available in container.

What it means

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.

Source

Thrown at src/Illuminate/Cache/CacheManager.php:405

                $config['key'] ?? '_cache',
            ),
            $config
        );
    }

    /**
     * Get the session store implementation.
     *
     * @return \Illuminate\Contracts\Session\Session
     *
     * @throws \InvalidArgumentException
     */
    protected function getSession()
    {
        $session = $this->app['session'] ?? null;

        if (! $session) {
            throw new InvalidArgumentException('Session store requires session manager to be available in container.');
        }

        return $session;
    }

    /**
     * Create a new cache repository with the given implementation.
     *
     * @param  \Illuminate\Contracts\Cache\Store  $store
     * @param  array  $config
     * @return \Illuminate\Cache\Repository
     */
    public function repository(Store $store, array $config = [])
    {
        return tap(new Repository($store, Arr::only($config, ['store'])), function ($repository) use ($config) {
            if ($config['events'] ?? true) {
                $this->setEventDispatcher($repository);
            }

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Use a non-session cache driver (redis, database, file) for code paths that run outside HTTP requests (queues, commands).
  2. Ensure Illuminate\Session\SessionServiceProvider is registered in config/app.php for HTTP-only usage.
  3. If you genuinely need session-backed caching, only resolve that store inside a middleware-covered request lifecycle.
  4. Switch CACHE_STORE to a durable driver and keep 'session' for request-scoped flash data only.

Example fix

// before
// config/cache.php uses 'session' driver; resolving in a queue worker:
Cache::store('session')->get('cart'); // throws

// after
// Use redis for cross-context caching:
Cache::store('redis')->get('cart');
// keep session store only inside HTTP request middleware
Defensive patterns

Strategy: validation

Validate before calling

if (app()->runningInConsole() && config('cache.stores.'.config('cache.default').'.driver') === 'session') {
    throw new \RuntimeException('Do not use the session cache driver in console/queue contexts.');
}
Cache::get('k');

Type guard

function sessionDriverIsSafe(): bool
{
    return app()->bound('session')
        && app()->make('request')->hasSession();
}

Try / catch

try {
    Cache::store('session')->get('k');
} catch (\InvalidArgumentException $e) {
    if (str_contains($e->getMessage(), 'session manager')) {
        return Cache::store('redis')->get('k');
    }
    throw $e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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'.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/0cf19ebbd623362b.json. Report an issue: GitHub.