{"id":"815f57a2bb21c094","repo":"laravel/framework","slug":"a-driver-must-be-specified","errorCode":null,"errorMessage":"A driver must be specified.","messagePattern":"A driver must be specified\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Connectors/ConnectionFactory.php","lineNumber":273,"sourceCode":"     * @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.\n     *\n     * @param  array  $config\n     * @return \\Illuminate\\Database\\Connectors\\ConnectorInterface\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function createConnector(array $config)\n    {\n        if (! isset($config['driver'])) {\n            throw new InvalidArgumentException('A driver must be specified.');\n        }\n\n        if ($this->container->bound($key = \"db.connector.{$config['driver']}\")) {\n            return $this->container->make($key);\n        }\n\n        return match ($config['driver']) {\n            'mysql' => new MySqlConnector,\n            'mariadb' => new MariaDbConnector,\n            'pgsql' => new PostgresConnector,\n            'sqlite' => new SQLiteConnector,\n            'sqlsrv' => new SqlServerConnector,\n            default => throw new InvalidArgumentException(\"Unsupported driver [{$config['driver']}].\"),\n        };\n    }\n\n    /**\n     * Create a new connection instance.","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Connectors/ConnectionFactory.php#L255-L291","documentation":"Thrown by ConnectionFactory::createConnector() when the 'driver' key is missing from the connection config array. Without a driver the factory cannot pick a Connector (MySQL/Postgres/SQLite/etc.) or a connection resolver.","triggerScenarios":"A connection config array passed to the factory without a 'driver' key. Common when DB_CONNECTION is unset in .env, when a custom connection was added to database.connections without a driver, or when config gets cached stale.","commonSituations":"Fresh checkout where .env is missing or DB_CONNECTION is blank; misnamed connection key; config:cache run with an incomplete .env; overriding config in tests and dropping the driver key.","solutions":["Set DB_CONNECTION in .env (e.g. mysql, pgsql, sqlite, sqlsrv).","Ensure every entry in config/database.php 'connections' has a 'driver' key.","Clear config cache: php artisan config:clear then config:cache after fixing.","Dump config to verify: php artisan tinker -> config('database.connections.mysql.driver')."],"exampleFix":"// before (.env)\nDB_CONNECTION=\n\n// after\nDB_CONNECTION=mysql","handlingStrategy":"validation","validationCode":"foreach (config('database.connections') as $name => $cfg) {\n    if (! isset($cfg['driver'])) {\n        throw new \\RuntimeException(\"Connection [$name] is missing a 'driver' key.\");\n    }\n}","typeGuard":"function hasDriver(array $config): bool {\n    return isset($config['driver']) && is_string($config['driver']) && $config['driver'] !== '';\n}","tryCatchPattern":null,"preventionTips":["Set DB_CONNECTION in .env for every environment.","Add a CI step that asserts config('database.connections.*.driver') is set.","Run config:clear after introducing a new connection.","Use a stub-checked .env.example so devs fill in DB_CONNECTION."],"tags":["configuration","connection","environment"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}