laravel/framework · error · InvalidArgumentException
Configuration value for key [%s] must be an integer, %s give
Error message
Configuration value for key [%s] must be an integer, %s given.
What it means
Thrown by Repository::integer() (src/Illuminate/Config/Repository.php:117) when the resolved config value is not a PHP int. The method uses is_int() (strict), so a numeric string coming from getenv/.env will fail. It is a fast-fail guard ensuring callers that asked for an integer-typed config value actually get one instead of silently receiving a string.
Source
Thrown at src/Illuminate/Config/Repository.php:117
return $value;
}
/**
* Get the specified integer configuration value.
*
* @param string $key
* @param (\Closure():(int|null))|int|null $default
* @return int
*
* @throws \InvalidArgumentException
*/
public function integer(string $key, $default = null): int
{
$value = $this->get($key, $default);
if (! is_int($value)) {
throw new InvalidArgumentException(
sprintf('Configuration value for key [%s] must be an integer, %s given.', $key, gettype($value))
);
}
return $value;
}
/**
* Get the specified float configuration value.
*
* @param string $key
* @param (\Closure():(float|null))|float|null $default
* @return float
*
* @throws \InvalidArgumentException
*/
public function float(string $key, $default = null): float
{View on GitHub (pinned to bd6b5437e6)
Solutions
- Cast the value in the config file: return (int) env('APP_FOO', 20); so the stored value is a real int.
- Provide an integer default at call site: config()->integer('app.pageSize', 20).
- If the value is legitimately string-ish, use string() and cast in the consumer: (int) config()->string('app.pageSize').
- Verify the key actually resolves — a missing key with no default yields null and fails the is_int check.
Example fix
// before
// config/app.php -> 'pageSize' => env('APP_PAGE_SIZE'),
$size = config()->integer('app.pageSize');
// after
// config/app.php -> 'pageSize' => (int) env('APP_PAGE_SIZE', 20),
$size = config()->integer('app.pageSize', 20); Defensive patterns
Strategy: validation
Validate before calling
$v = config('app.pageSize');
if (! is_int($v)) {
// fix the config source or coerce before calling integer()
} Type guard
function isIntConfig(\Illuminate\Config\Repository $c, string $key): bool
{
return is_int($c->get($key));
} Try / catch
try {
$size = config()->integer('app.pageSize', 20);
} catch (\InvalidArgumentException $e) {
$size = 20; // safe fallback
logger()->warning($e->getMessage());
} Prevention
- Always cast env-backed values in config files: (int) env('KEY', default).
- Provide integer defaults when calling integer().
- Centralize config accessors and unit-test them with sample .env values.
When it happens
Trigger: Calling config()->integer('app.pageSize') or Config::get(...) wrapped via the integer() accessor when the stored value is a string like "20", a float, null (no default given), bool, or array. Also triggered by passing a non-int default (e.g. integer('k', "0")).
Common situations: Env values are always strings in PHP, so integer('app.foo') backed by env('APP_FOO') almost always fails unless env was cast via env('APP_FOO', 0) with an integer default and envvar not set, or via (int) casts in config files. New in Laravel (added alongside typed accessors), so code migrated from get() to integer() commonly trips this.
Related errors
- Configuration value for key [%s] must be a float, %s given.
- Configuration value for key [%s] must be a boolean, %s given
- Configuration value for key [%s] must be an array, %s given.
- Configuration value for key [%s] must be a string, %s given.
- This cache store does not support locks.
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/a96db52e1e475077.json.
Report an issue: GitHub.