laravel/framework · error · InvalidArgumentException
Configuration value for key
Error message
Configuration value for key [%s] must be a string, %s given.
What it means
Thrown by Config\Repository::string(string $key) when the stored value is not a string (after applying any default). This is the typed config accessor introduced for strict retrieval; is_string($value) is checked and an InvalidArgumentException reports the key and the actual gettype(). A null result from a missing key (with no default) also triggers it because null is not a string.
Solutions
- Provide a string default: Config::string('app.locale', 'en').
- Ensure the underlying config/env value is a string (quote env values: APP_KEY='base64:...').
- Use Config::get() if you need to tolerate non-string values, or cast at the source.
Example fix
// before
$locale = Config::string('app.locale');
// after
$locale = Config::string('app.locale', 'en');
// and in .env ensure: APP_LOCALE=en Defensive patterns
Strategy: type-guard
Validate before calling
$value = Config::get('app.locale');
if (! is_string($value)) {
throw new \InvalidArgumentException('app.locale must be a string');
} Type guard
function configIsString(string $key): bool {
return is_string(Config::get($key));
} Try / catch
try {
$locale = Config::string('app.locale');
} catch (\InvalidArgumentException $e) {
$locale = 'en'; // safe fallback
} Prevention
- Always provide a string default to Config::string().
- Quote env values and ensure config files store strings.
- Validate required string config at boot and fail loudly with a clear message.
When it happens
Trigger: Config::string('app.key') where app.key is null/missing/int/bool; reading an env-backed value that resolved to a non-string; providing a default that is itself not a string.
Common situations: An env var is unset so the config returns null; a config file stores an int/bool where a string was expected; typed accessor used during early bootstrap before config is loaded.
Related errors
- Configuration value for key
- Configuration value for key
- Collection should only include
- A driver must be specified.
- Ably error
AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11).
Data as JSON: /api/errors/42f858169739475e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Config/Repository.php:95
return $config;
}
/**
* Get the specified string configuration value.
*
* @param string $key
* @param (\Closure():(string|null))|string|null $default
* @return string
*
* @throws \InvalidArgumentException
*/
public function string(string $key, $default = null): string
{
$value = $this->get($key, $default);
if (! is_string($value)) {
throw new InvalidArgumentException(
sprintf('Configuration value for key [%s] must be a string, %s given.', $key, gettype($value))
);
}
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
{View on GitHub (pinned to e0f6eb3518)