{"id":"8d35392331a63e07","repo":"laravel/framework","slug":"configuration-value-for-key-s-must-be-an-array","errorCode":null,"errorMessage":"Configuration value for key [%s] must be an array, %s given.","messagePattern":"Configuration value for key \\[(.+?)\\] must be an array, (.+?) given\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Config/Repository.php","lineNumber":183,"sourceCode":"\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    {\n        $value = $this->get($key, $default);\n\n        if (! is_array($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Configuration value for key [%s] must be an array, %s given.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Get the specified array configuration value as a collection.\n     *\n     * @param  string  $key\n     * @param  (\\Closure():(array<array-key, mixed>|null))|array<array-key, mixed>|null  $default\n     * @return Collection<array-key, mixed>\n     */\n    public function collection(string $key, $default = null): Collection\n    {\n        return new Collection($this->array($key, $default));\n    }","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Config/Repository.php#L165-L201","documentation":"Thrown by Repository::array() (src/Illuminate/Config/Repository.php:183) when the resolved value is not an array. is_array() is strict, so comma-separated strings, JSON strings, null, or scalars fail.","triggerScenarios":"Calling config()->array('services.stripe.webhooks') when the stored value is a string, null (missing key with no default), or a comma-separated list. JSON-encoded values also fail because they are strings until decoded.","commonSituations":"Developers store lists as comma-separated env strings (e.g. CORS origins) but then access via array(). Also triggered when a config file omits a key entirely and no default is supplied.","solutions":["Define the config value as an actual array in the config file: 'origins' => explode(',', env('CORS_ORIGINS', '')), or a literal array.","Pass an array default at call site: config()->array('cors.origins', []).","If the value is JSON, decode it in the config file: json_decode(env('X', '[]'), true).","Confirm the config file is loaded and the key path is correct."],"exampleFix":"// before\n// 'webhooks' => env('STRIPE_WEBHOOKS'),  // string\nconfig()->array('services.stripe.webhooks');\n\n// after\n// 'webhooks' => explode(',', env('STRIPE_WEBHOOKS', '')),\nconfig()->array('services.stripe.webhooks', []);","handlingStrategy":"validation","validationCode":"$v = config('cors.origins');\nif (! is_array($v)) {\n    // ensure config returns an array, decode JSON, or explode a CSV string\n}","typeGuard":"function isArrayConfig(\\Illuminate\\Config\\Repository $c, string $key): bool\n{\n    return is_array($c->get($key));\n}","tryCatchPattern":"try {\n    $origins = config()->array('cors.origins', []);\n} catch (\\InvalidArgumentException $e) {\n    $origins = [];\n}","preventionTips":["Store lists as arrays in config files; explode CSV strings from env.","Always pass an array default at the call site.","Avoid JSON strings in config — decode them in the config file."],"tags":["config","type-coercion","env","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}