{"record":{"id":"d600cfdce72165e8","repo":"laravel/framework","slug":"cache-value-for-key-s-must-be-a-boolean-s-giv","errorCode":null,"errorMessage":"Cache value for key [%s] must be a boolean, %s given.","messagePattern":"Cache value for key \\[(.+?)\\] must be a boolean, (.+?) given\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Cache/Repository.php","lineNumber":327,"sourceCode":"        );\n    }\n\n    /**\n     * Retrieve a boolean item from the cache.\n     *\n     * @param  \\UnitEnum|string  $key\n     * @param  (\\Closure():(bool|null))|bool|null  $default\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function boolean($key, $default = null): bool\n    {\n        $key = enum_value($key);\n\n        $value = $this->get($key, $default);\n\n        if (! is_bool($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Cache value for key [%s] must be a boolean, %s given.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Retrieve an array item from the cache.\n     *\n     * @param  \\UnitEnum|string  $key\n     * @param  (\\Closure():(array<array-key, mixed>|null))|array<array-key, mixed>|null  $default\n     * @return array<array-key, mixed>\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function array($key, $default = null): array\n    {","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Cache/Repository.php#L309-L345","documentation":"Thrown by Repository::boolean() when the value is not strictly a bool. Unlike integer()/float(), there is NO filter_var coercion here, so strings '1'/'true'/'on', integer 1/0, and null all fail. Only actual true/false values pass.","triggerScenarios":"Calling Cache::boolean('key') where the stored value is anything other than a literal PHP bool, including truthy strings, 0/1 ints, or null from a cache miss.","commonSituations":"Storing config flags as 1/0 or 'true' strings; migrating from get() with manual (bool) casts; cache miss without a bool default.","solutions":["Pass a bool default: Cache::boolean('key', false).","Store actual booleans: Cache::put('flag', (bool) $flag).","If you must accept '1'/'0'/'true', read with get() and cast manually."],"exampleFix":"// before\n$enabled = Cache::boolean('feature.x'); // stored as '1' throws\n// after\n$enabled = Cache::boolean('feature.x', false);\n// or normalize at write time:\nCache::put('feature.x', (bool) $request->input('x'));","handlingStrategy":"validation","validationCode":"// No coercion in boolean(); normalize input first.\n$raw = Cache::get($key);\nif ($raw !== null) {\n    $raw = filter_var($raw, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);\n    if ($raw === null) { /* not boolean-like */ }\n}\n$val = Cache::boolean($key, false);","typeGuard":"function isCacheBooleanable(mixed $value): bool { return is_bool($value); }","tryCatchPattern":"try {\n    $enabled = Cache::boolean('feature');\n} catch (\\InvalidArgumentException $e) {\n    $enabled = false;\n}","preventionTips":["Store actual PHP booleans, never 1/0 or 'true'.","Always pass a bool default.","Use filter_var(..., FILTER_VALIDATE_BOOLEAN) to normalize external input before caching."],"tags":["cache","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"}