{"record":{"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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Collections/Arr.php#L87-L123","documentation":"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.","triggerScenarios":"Calling Arr::boolean($data, 'key') where the value is a non-bool (string 'true', int 1, null from a miss).","commonSituations":"Parsing form/API input where booleans arrive as '1'/0 strings; assuming config flags are bools when they are strings.","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."],"exampleFix":"// before\n$ok = Arr::boolean($input, 'enabled'); // stored as '1' throws\n// after\n$ok = Arr::boolean($input, 'enabled', false);\n// or normalize:\n$input['enabled'] = filter_var($input['enabled'] ?? false, FILTER_VALIDATE_BOOLEAN);","handlingStrategy":"validation","validationCode":"$raw = Arr::get($data, 'enabled');\nif (! is_bool($raw)) {\n    $raw = filter_var($raw, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false;\n}\n// Then read with bool in hand, or normalize source before lookup.","typeGuard":"function isStrictBool(mixed $value): bool { return is_bool($value); }","tryCatchPattern":"try {\n    $ok = Arr::boolean($input, 'enabled');\n} catch (\\InvalidArgumentException $e) {\n    $ok = false;\n}","preventionTips":["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."],"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"}