{"id":"3298ca42eed71d65","repo":"laravel/framework","slug":"configuration-value-for-key-s-must-be-a-boolean","errorCode":null,"errorMessage":"Configuration value for key [%s] must be a boolean, %s given.","messagePattern":"Configuration value for key \\[(.+?)\\] must be a boolean, (.+?) given\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Config/Repository.php","lineNumber":161,"sourceCode":"\n        return $value;\n    }\n\n    /**\n     * Get the specified boolean configuration value.\n     *\n     * @param  string  $key\n     * @param  (\\Closure():(bool|null))|bool|null  $default\n     * @return bool\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function boolean(string $key, $default = null): bool\n    {\n        $value = $this->get($key, $default);\n\n        if (! is_bool($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Configuration value for key [%s] must be a boolean, %s given.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Get the specified array configuration value.\n     *\n     * @param  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(string $key, $default = null): array\n    {","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Config/Repository.php#L143-L179","documentation":"Thrown by Repository::boolean() (src/Illuminate/Config/Repository.php:161) when the resolved value is not a real bool. is_bool() is strict: the strings \"true\"/\"false\", 1/0, or null from env all fail.","triggerScenarios":"Calling config()->boolean('app.debug') when the value is the env string \"true\", an integer 1, or null. The classic trap is env('APP_DEBUG') returning \"true\" (string) rather than true (bool).","commonSituations":"Laravel's env loader casts a handful of literal strings, but only when the value comes through env() without a cached config. After config:cache, raw getenv() strings can persist. Also a problem for boolean env values that a user sets as 1/0 in .env.","solutions":["Cast explicitly in the config file: 'debug' => filter_var(env('APP_DEBUG', false), FILTER_VALIDATE_BOOLEAN),.","Provide a bool default at call site: config()->boolean('app.debug', false).","After changing .env, run php artisan config:clear then config:cache so env casts are re-evaluated.","Avoid mixing integer 1/0 semantics with the boolean accessor."],"exampleFix":"// before\n// 'debug' => env('APP_DEBUG'),  // getenv returns string\nconfig()->boolean('app.debug');\n\n// after\n// 'debug' => filter_var(env('APP_DEBUG', false), FILTER_VALIDATE_BOOLEAN),\nconfig()->boolean('app.debug', false);","handlingStrategy":"validation","validationCode":"$v = config('app.debug');\nif (! is_bool($v)) {\n    // fix config source; strings 'true'/'1' will fail\n}","typeGuard":"function isBoolConfig(\\Illuminate\\Config\\Repository $c, string $key): bool\n{\n    return is_bool($c->get($key));\n}","tryCatchPattern":"try {\n    $debug = config()->boolean('app.debug', false);\n} catch (\\InvalidArgumentException $e) {\n    $debug = false;\n}","preventionTips":["Use filter_var(..., FILTER_VALIDATE_BOOLEAN) in config files for env booleans.","Provide a bool default at the call site.","Run config:clear after .env changes."],"tags":["config","type-coercion","env","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}