{"record":{"id":"31abd383ab5d1920","repo":"laravel/framework","slug":"cache-store-name-is-not-defined","errorCode":null,"errorMessage":"Cache store [{$name}] is not defined.","messagePattern":"Cache store \\[(.+?)\\] is not defined\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Cache/CacheManager.php","lineNumber":121,"sourceCode":"        });\n\n        return $this->app->make($bindingKey);\n    }\n\n    /**\n     * Resolve the given store.\n     *\n     * @param  string  $name\n     * @return \\Illuminate\\Contracts\\Cache\\Repository\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function resolve($name)\n    {\n        $config = $this->getConfig($name);\n\n        if (is_null($config)) {\n            throw new InvalidArgumentException(\"Cache store [{$name}] is not defined.\");\n        }\n\n        $config = Arr::add($config, 'store', $name);\n\n        return $this->build($config);\n    }\n\n    /**\n     * Build a cache repository with the given configuration.\n     *\n     * @param  array  $config\n     * @return \\Illuminate\\Cache\\Repository\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function build(array $config)\n    {\n        $config = Arr::add($config, 'store', $config['name'] ?? 'ondemand');","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Cache/CacheManager.php#L103-L139","documentation":"CacheManager::resolve looks up the named store's configuration via getConfig(). If no matching key exists in the 'stores' array of config/cache.php (or the runtime config), getConfig returns null and the manager refuses to silently fall back. The named store must be declared before it can be used.","triggerScenarios":"Calling Cache::store('redis-secondary')->get('key') when 'redis-secondary' is not declared under config/cache.php 'stores'. Also via Cache::driver('missing')->... or any code path that calls CacheManager::resolve with an undeclared store name, including config:cache dumping a stale cache config.","commonSituations":"Typos in store name (e.g., 'redjs' vs 'redis'). Adding a new store but forgetting to clear php artisan config:cache. Environment-specific stores defined in .env (CACHE_STORE_SECONDARY) never wired into config. Multi-tenant code selecting a tenant-scoped store that isn't registered.","solutions":["Add an entry under 'stores' in config/cache.php with the requested name and a valid driver.","Run php artisan config:clear to remove stale cached config, then re-cache with config:cache after editing.","Check for typos: the name passed to Cache::store() must exactly match a key in config/cache.php 'stores'.","If the store is dynamic, register it at runtime via Cache::store('name', $repository) before first use."],"exampleFix":"// before\nCache::store('redis-secondary')->get('key');\n// config/cache.php 'stores' has only 'redis', not 'redis-secondary'\n\n// after - in config/cache.php\n'stores' => [\n    // ...\n    'redis-secondary' => [\n        'driver' => 'redis',\n        'connection' => 'cache-secondary',\n    ],\n],","handlingStrategy":"validation","validationCode":"// Validate the store name is declared before resolving\n$name = 'redis-secondary';\nif (is_null(config(\"cache.stores.{$name}\"))) {\n    throw new \\RuntimeException(\"Cache store [{$name}] is not declared in config/cache.php.\");\n}\nCache::store($name)->get('key');","typeGuard":"function cacheStoreIsDeclared(string $name): bool\n{\n    return ! is_null(config(\"cache.stores.{$name}\"));\n}","tryCatchPattern":"try {\n    Cache::store($name)->get('key');\n} catch (\\InvalidArgumentException $e) {\n    if (str_starts_with($e->getMessage(), 'Cache store [')) {\n        logger()->error('Undeclared cache store requested', ['store' => $name]);\n        // fall back to default\n        return Cache::get('key');\n    }\n    throw $e;\n}","preventionTips":["Centralize cache store selection in a config service; validate names at boot.","Always run php artisan config:clear after editing config/cache.php.","Use enums or constants for store names to prevent typos.","Add a smoke test that resolves every configured store name."],"tags":["cache","configuration","store-lookup"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}