laravel/framework · error · InvalidArgumentException
Configuration value for key
Error message
Configuration value for key [%s] must be a float, %s given.
What it means
Thrown by Config\Repository::float(string $key) when the stored value is not a float. The check is is_float($value); note that an int value (e.g. 5) is NOT a float in PHP's strict sense and will fail this check, as will numeric strings, bools, and null. InvalidArgumentException reports the key and the actual type.
Solutions
- Cast the value to float in the config file: (float) env('PAYMENT_FEE', 0.0).
- Provide a float default: Config::float('payment.fee', 0.0).
- Ensure the stored literal is a float (e.g. 5.0, not 5) when you control the config.
Example fix
// before
// config: 'fee' => env('PAYMENT_FEE', 5), // int default
$fee = Config::float('payment.fee');
// after
// config: 'fee' => (float) env('PAYMENT_FEE', 5.0),
$fee = Config::float('payment.fee', 5.0); Defensive patterns
Strategy: type-guard
Validate before calling
$value = Config::get('payment.fee');
if (! is_float($value)) {
throw new \InvalidArgumentException('payment.fee must be float');
} Type guard
function configIsFloat(string $key): bool {
return is_float(Config::get($key));
} Try / catch
try {
$fee = Config::float('payment.fee');
} catch (\InvalidArgumentException $e) {
$fee = 0.0; // safe default
} Prevention
- Cast env-backed values to float in config files: (float) env('KEY', 0.0).
- Remember an int literal (5) is NOT a float — write 5.0 when needed.
- Provide a float default to Config::float() to cover missing keys.
When it happens
Trigger: Config::float('payment.fee') where the config stores 5 (int), '5.0' (string), or null; reading an env-backed value without a float cast.
Common situations: Config file stores a literal integer where a float was expected; env returns a string; missing key with no float default. The int-vs-float strictness is the most common surprise.
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/771101f1e289f224.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Config/Repository.php:139
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
{
$value = $this->get($key, $default);
if (! is_float($value)) {
throw new InvalidArgumentException(
sprintf('Configuration value for key [%s] must be a float, %s given.', $key, gettype($value))
);
}
return $value;
}
/**
* Get the specified boolean configuration value.
*
* @param string $key
* @param (\Closure():(bool|null))|bool|null $default
* @return bool
*
* @throws \InvalidArgumentException
*/
public function boolean(string $key, $default = null): bool
{View on GitHub (pinned to e0f6eb3518)