{"record":{"id":"3da5627d6fcdc23f","repo":"laravel/framework","slug":"database-hosts-array-is-empty","errorCode":null,"errorMessage":"Database hosts array is empty.","messagePattern":"Database hosts array is empty\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Connectors/ConnectionFactory.php","lineNumber":245,"sourceCode":"                throw $exception;\n            }\n        };\n    }\n\n    /**\n     * Parse the hosts configuration item into an array.\n     *\n     * @param  array  $config\n     * @return array\n     *\n     * @throws \\InvalidArgumentException\n     */\n    protected function parseHosts(array $config)\n    {\n        $hosts = Arr::wrap($config['host']);\n\n        if (empty($hosts)) {\n            throw new InvalidArgumentException('Database hosts array is empty.');\n        }\n\n        return $hosts;\n    }\n\n    /**\n     * Create a new Closure that resolves to a PDO instance where there is no configured host.\n     *\n     * @param  array  $config\n     * @return \\Closure\n     */\n    protected function createPdoResolverWithoutHosts(array $config)\n    {\n        return fn () => $this->createConnector($config)->connect($config);\n    }\n\n    /**\n     * Create a connector instance based on the configuration.","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Connectors/ConnectionFactory.php#L227-L263","documentation":"Thrown by ConnectionFactory::parseHosts() when Arr::wrap($config['host']) is empty. The factory iterates the hosts array to build a read/write PDO resolver per host, so an empty list (missing host, blank string, or empty array) is rejected before any connection attempt. SQLite connections are exempt because they go through a host-less resolver path.","triggerScenarios":"A connection config where 'host' is missing, set to '' (which Arr::wrap keeps as a one-element empty array after trimming in some paths), or set to []. Triggered when DatabaseManager/Capsule first builds the connection.","commonSituations":".env with DB_HOST empty or unset for a mysql/pgsql/sqlsrv connection; config/database.php 'host' => env('DB_HOST') resolving to null; multiple-host config with all entries removed; deploying without copying .env.","solutions":["Set DB_HOST in .env (e.g. DB_HOST=127.0.0.1) and confirm it is read by config/database.php.","Ensure the 'host' key in the connection config is a non-empty string or a non-empty array.","For socket-only MySQL, set the host to 'localhost' and configure the unix_socket option rather than leaving host blank.","If you intentionally have no host (SQLite), set the connection driver to 'sqlite' so parseHosts is not invoked."],"exampleFix":"// before (config/database.php)\n'mysql' => ['driver' => 'mysql', 'host' => env('DB_HOST') /* empty */],\n\n// after\n'mysql' => ['driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1')],","handlingStrategy":"validation","validationCode":"$hosts = \\Illuminate\\Support\\Arr::wrap($config['host'] ?? null);\nif (empty($hosts) || array_filter($hosts) === []) {\n    throw new \\InvalidArgumentException('DB host missing: set DB_HOST.');\n}","typeGuard":"function hasNonEmptyHost(array $config): bool {\n    $hosts = \\Illuminate\\Support\\Arr::wrap($config['host'] ?? null);\n    return ! empty(array_filter($hosts));\n}","tryCatchPattern":null,"preventionTips":["Always provide a fallback default in config: 'host' => env('DB_HOST', '127.0.0.1').","Fail fast in CI by asserting DB_HOST is non-empty before bootstrapping the app.","For SQLite, use the 'sqlite' driver so the host parser is bypassed."],"tags":["database","configuration","connection","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}