laravel/framework · error · InvalidArgumentException

Session store requires session manager to be available in…

Error message

Session store requires session manager to be available in container.

What it means

CacheManager::getSession backs the 'session' cache driver — it returns the bound session manager from the container (app('session')). When the session service provider has not been registered (e.g., using illuminate/cache standalone, or in an API-only app with sessions disabled), the 'session' binding is absent and the cache driver cannot be constructed.

Solutions

  1. Register Illuminate\Session\SessionServiceProvider in config/app.php (or bootstrap/app.php providers in Laravel 11+).
  2. If sessions are intentionally disabled, switch the cache store's 'driver' to a supported alternative (array, file, redis) and remove the 'session' cache store entry.
  3. Ensure the session middleware is on the route stack for the request that initializes the session-bound cache.

Example fix

// before - bootstrap/app.php (Laravel 11+) without session provider, but config/cache.php declares:
'stores' => [
    'session-cache' => ['driver' => 'session'],
],

// after - register the provider
->withProviders([
    Illuminate\Session\SessionServiceProvider::class,
])
// OR remove the 'session' cache store entry if sessions are unused
Defensive patterns

Strategy: validation

Validate before calling

// Validate the session binding exists before using a session cache driver
if (config('cache.stores.session.driver') === 'session' && ! app()->bound('session')) {
    throw new \RuntimeException('Session cache driver requires SessionServiceProvider to be registered.');
}

Type guard

function sessionManagerIsBound(): bool
{
    return app()->bound('session');
}

Prevention

When it happens

Trigger: Configuring a cache store with 'driver' => 'session' in config/cache.php while Illuminate\Session\SessionServiceProvider is not registered. Calling Cache::store('session') in a stateless API stack (Laravel Sanctum without web middleware) where sessions were intentionally removed.

Common situations: API-only Laravel app that removed SessionServiceProvider to avoid session overhead but still has a stale 'session' cache store. Standalone illuminate/cache usage in a non-Laravel script. Custom application bootstrap that omits session provider.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/0cf19ebbd623362b. Report an issue: GitHub.

Appendix: 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 e0f6eb3518)