{"record":{"id":"a96db52e1e475077","repo":"laravel/framework","slug":"configuration-value-for-key-s-must-be-an-intege","errorCode":null,"errorMessage":"Configuration value for key [%s] must be an integer, %s given.","messagePattern":"Configuration value for key \\[(.+?)\\] must be an integer, (.+?) given\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Config/Repository.php","lineNumber":117,"sourceCode":"\n        return $value;\n    }\n\n    /**\n     * Get the specified integer configuration value.\n     *\n     * @param  string  $key\n     * @param  (\\Closure():(int|null))|int|null  $default\n     * @return int\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function integer(string $key, $default = null): int\n    {\n        $value = $this->get($key, $default);\n\n        if (! is_int($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Configuration value for key [%s] must be an integer, %s given.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Get the specified float configuration value.\n     *\n     * @param  string  $key\n     * @param  (\\Closure():(float|null))|float|null  $default\n     * @return float\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function float(string $key, $default = null): float\n    {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Config/Repository.php#L99-L135","documentation":"Thrown by Config\\Repository::integer(string $key) when the stored value is not an int. The typed accessor checks is_int($value) strictly; a numeric string from env (e.g. '5'), a float, bool, or null all fail and throw InvalidArgumentException with the key and gettype(). Unlike some accessors this does not coerce — the value must already be a PHP int.","triggerScenarios":"Config::integer('cache.ttl') where the env/config stores '300' (string) or 300.0 (float); reading a value that is null because the key is absent and no default is given.","commonSituations":"Env vars are always strings, so an integer config backed by env() without an explicit cast fails; mixing integer() with values typed elsewhere as strings; missing default for an optional key.","solutions":["Cast the env value in the config file: env('CACHE_TTL', 300) with an int default, or (int) env(...).","Provide an int default: Config::integer('cache.ttl', 300).","Use Config::get() and cast at the call site if you cannot change the config source."],"exampleFix":"// before\n// config file: 'ttl' => env('CACHE_TTL'),  // env returns string|null\n$ttl = Config::integer('cache.ttl');\n// after\n// config file: 'ttl' => (int) env('CACHE_TTL', 300),\n$ttl = Config::integer('cache.ttl', 300);","handlingStrategy":"type-guard","validationCode":"$value = Config::get('cache.ttl');\nif (! is_int($value)) {\n    throw new \\InvalidArgumentException('cache.ttl must be int');\n}","typeGuard":"function configIsInt(string $key): bool {\n    return is_int(Config::get($key));\n}","tryCatchPattern":"try {\n    $ttl = Config::integer('cache.ttl');\n} catch (\\InvalidArgumentException $e) {\n    $ttl = 300; // safe default\n}","preventionTips":["Cast env-backed values to int in config files: (int) env('KEY', 300).","Provide an int default to Config::integer().","Remember env() always returns string|null — never assume int without a cast."],"tags":["config","type-safety","env","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}