{"id":"b97f7e492e2ed88c","repo":"laravel/framework","slug":"array-value-for-key-s-must-be-a-boolean-s-fou","errorCode":null,"errorMessage":"Array value for key [%s] must be a boolean, %s found.","messagePattern":"Array value for key \\[(.+?)\\] must be a boolean, (.+?) found\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Collections/Arr.php","lineNumber":105,"sourceCode":"            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(\n                sprintf('Array value for key [%s] must be a boolean, %s found.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Collapse an array of arrays into a single array.\n     *\n     * @param  iterable  $array\n     * @return array\n     */\n    public static function collapse($array)\n    {\n        $results = [];\n\n        foreach ($array as $values) {","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Collections/Arr.php#L87-L123","documentation":"Thrown by Arr::boolean() when the value resolved via Arr::get() fails is_bool(). The accessor does not coerce 0/1/'true', so those values and null all trigger it.","triggerScenarios":"Calling Arr::boolean($data, 'enabled') when the value is 1, 0, 'true', 'false', an array, or null (missing key, no bool default).","commonSituations":"Decoding JSON whose booleans came through as 'true'/'false' strings; reading a database/config value stored as tinyint(1) yielding 0/1; missing key with no default.","solutions":["Pass a bool default: Arr::boolean($data, 'enabled', false).","Normalize the source: cast with filter_var($v, FILTER_VALIDATE_BOOLEAN) before storing/reading.","Validate first: $v = Arr::get($data, 'enabled'); if (is_bool($v)) { ... }.","Fix the dot path or schema so the key genuinely contains a bool."],"exampleFix":"// before\n$on = Arr::boolean($payload, 'features.beta');\n\n// after\n$on = Arr::boolean($payload, 'features.beta', false);\n// or normalize\n$raw = Arr::get($payload, 'features.beta');\n$on = is_bool($raw) ? $raw : filter_var($raw, FILTER_VALIDATE_BOOLEAN);","handlingStrategy":"type-guard","validationCode":"$value = Arr::get($data, 'enabled');\nif (! is_bool($value)) {\n    $value = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false;\n}","typeGuard":"function arrayKeyIsBool(array $array, string $key): bool {\n    return is_bool(Arr::get($array, $key));\n}","tryCatchPattern":"try {\n    $on = Arr::boolean($data, 'enabled', false);\n} catch (\\InvalidArgumentException $e) {\n    $on = false;\n}","preventionTips":["Normalize truthy/falsy values with filter_var(FILTER_VALIDATE_BOOLEAN) before reading.","Pass a bool default to Arr::boolean().","Avoid storing flags as 0/1 ints where they will be read as bools."],"tags":["collections","arrays","type-mismatch","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}