laravel/framework · error · InvalidArgumentException
Array value for key [ ] must be an array, found.
Error message
Array value for key [%s] must be an array, %s found.
What it means
Thrown by Arr::array() when the value resolved from Arr::get() (dot-notation lookup) is not an array. Like the Cache equivalent, a missing key with no default yields null and fails.
Solutions
- Pass an array default: Arr::array($data, 'key', []).
- Validate the structure before reading with Arr::has() / is_array().
- Normalize the source (json_decode with true to force arrays).
Example fix
// before $list = Arr::array($payload, 'items'); // throws if missing // after $list = Arr::array($payload, 'items', []);
Defensive patterns
Strategy: validation
Validate before calling
// Pass an array default; or check structure first.
if (Arr::has($data, 'items') && is_array(Arr::get($data, 'items'))) {
$items = Arr::array($data, 'items');
} else {
$items = [];
} Type guard
function isArrayOf(mixed $value): bool { return is_array($value); } Try / catch
try {
$items = Arr::array($payload, 'items');
} catch (\InvalidArgumentException $e) {
$items = [];
} Prevention
- Pass an array default to Arr::array().
- Decode JSON with json_decode($json, true) to force nested arrays.
- Validate third-party payload shapes before reading.
When it happens
Trigger: Calling Arr::array($data, 'nested.key') where nested.key is a scalar, null, or absent and $default is null.
Common situations: Decoding JSON config and assuming nested arrays; third-party API responses where a field is sometimes scalar; missing keys in user-supplied input.
Related errors
- Array value for key [ ] must be a boolean, found.
- 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 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/7a23830f98eab860.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Collections/Arr.php:87
{
if (is_null(static::get($array, $key))) {
static::set($array, $key, $value);
}
return $array;
}
/**
* Get an array item from an array using "dot" notation.
*
* @throws \InvalidArgumentException
*/
public static function array(ArrayAccess|array $array, string|int|null $key, ?array $default = null): array
{
$value = Arr::get($array, $key, $default);
if (! is_array($value)) {
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(View on GitHub (pinned to e0f6eb3518)