{"record":{"id":"7a23830f98eab860","repo":"laravel/framework","slug":"array-value-for-key-s-must-be-an-array-s-foun","errorCode":null,"errorMessage":"Array value for key [%s] must be an array, %s found.","messagePattern":"Array value for key \\[(.+?)\\] must be an array, (.+?) found\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Collections/Arr.php","lineNumber":87,"sourceCode":"    {\n        if (is_null(static::get($array, $key))) {\n            static::set($array, $key, $value);\n        }\n\n        return $array;\n    }\n\n    /**\n     * Get an array item from an array using \"dot\" notation.\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function array(ArrayAccess|array $array, string|int|null $key, ?array $default = null): array\n    {\n        $value = Arr::get($array, $key, $default);\n\n        if (! is_array($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Array value for key [%s] must be an array, %s found.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Get a boolean item from an array using \"dot\" notation.\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function boolean(ArrayAccess|array $array, string|int|null $key, ?bool $default = null): bool\n    {\n        $value = Arr::get($array, $key, $default);\n\n        if (! is_bool($value)) {\n            throw new InvalidArgumentException(","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Collections/Arr.php#L69-L105","documentation":"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.","triggerScenarios":"Calling Arr::array($data, 'nested.key') where nested.key is a scalar, null, or absent and $default is null.","commonSituations":"Decoding JSON config and assuming nested arrays; third-party API responses where a field is sometimes scalar; missing keys in user-supplied input.","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)."],"exampleFix":"// before\n$list = Arr::array($payload, 'items'); // throws if missing\n// after\n$list = Arr::array($payload, 'items', []);","handlingStrategy":"validation","validationCode":"// Pass an array default; or check structure first.\nif (Arr::has($data, 'items') && is_array(Arr::get($data, 'items'))) {\n    $items = Arr::array($data, 'items');\n} else {\n    $items = [];\n}","typeGuard":"function isArrayOf(mixed $value): bool { return is_array($value); }","tryCatchPattern":"try {\n    $items = Arr::array($payload, 'items');\n} catch (\\InvalidArgumentException $e) {\n    $items = [];\n}","preventionTips":["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."],"tags":["collections","array","type-mismatch","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}