laravel/framework · error · InvalidArgumentException
Array value for key [ ] must be a boolean, found.
Error message
Array value for key [%s] must be a boolean, %s found.
What it means
Thrown by Arr::boolean() when the resolved dot-notation value is not strictly a bool. No coercion: strings '1'/'true', ints 1/0, and null all fail.
Solutions
- Pass a bool default: Arr::boolean($data, 'key', false).
- Normalize input: filter_var($value, FILTER_VALIDATE_BOOLEAN) before storing.
- Use Arr::get() and cast manually if mixed truthy values are expected.
Example fix
// before $ok = Arr::boolean($input, 'enabled'); // stored as '1' throws // after $ok = Arr::boolean($input, 'enabled', false); // or normalize: $input['enabled'] = filter_var($input['enabled'] ?? false, FILTER_VALIDATE_BOOLEAN);
Defensive patterns
Strategy: validation
Validate before calling
$raw = Arr::get($data, 'enabled');
if (! is_bool($raw)) {
$raw = filter_var($raw, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false;
}
// Then read with bool in hand, or normalize source before lookup. Type guard
function isStrictBool(mixed $value): bool { return is_bool($value); } Try / catch
try {
$ok = Arr::boolean($input, 'enabled');
} catch (\InvalidArgumentException $e) {
$ok = false;
} Prevention
- Normalize booleans with filter_var(..., FILTER_VALIDATE_BOOLEAN) at the input boundary.
- Pass a bool default.
- Document strict-bool semantics so callers do not expect coercion.
When it happens
Trigger: Calling Arr::boolean($data, 'key') where the value is a non-bool (string 'true', int 1, null from a miss).
Common situations: Parsing form/API input where booleans arrive as '1'/0 strings; assuming config flags are bools when they are strings.
Related errors
- Array value for key [ ] must be a float, found.
- Array value for key [ ] must be a string, found.
- Array value for key [ ] must be an array, found.
- Array value for key [ ] must be an integer, found.
- Items cannot be represented by a scalar value.
AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11).
Data as JSON: /api/errors/b97f7e492e2ed88c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Collections/Arr.php:105
throw new InvalidArgumentException(
sprintf('Array value for key [%s] must be an array, %s found.', $key, gettype($value))
);
}
return $value;
}
/**
* Get a boolean item from an array using "dot" notation.
*
* @throws \InvalidArgumentException
*/
public static function boolean(ArrayAccess|array $array, string|int|null $key, ?bool $default = null): bool
{
$value = Arr::get($array, $key, $default);
if (! is_bool($value)) {
throw new InvalidArgumentException(
sprintf('Array value for key [%s] must be a boolean, %s found.', $key, gettype($value))
);
}
return $value;
}
/**
* Collapse an array of arrays into a single array.
*
* @param iterable $array
* @return array
*/
public static function collapse($array)
{
$results = [];
foreach ($array as $values) {View on GitHub (pinned to e0f6eb3518)