{"record":{"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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Connectors/ConnectionFactory.php#L255-L291","documentation":"Thrown by ConnectionFactory::createConnector() when the config array has no 'driver' key. The factory dispatches to a concrete Connector (MySQL, Postgres, SQLite, SQL Server) based on the driver string; without it there is no way to choose one, so it fails immediately rather than guessing.","triggerScenarios":"Calling $factory->createConnector($config) (directly, or via DatabaseManager when a connection is first opened) where $config['driver'] is unset. Triggered the first time DB::connection($name) is resolved.","commonSituations":".env with DB_CONNECTION empty; config/database.php connection entry missing the 'driver' line; a connection name referenced in code that maps to an incomplete config stub; typo in the env var name read by the driver key.","solutions":["Add 'driver' => env('DB_CONNECTION', 'mysql') to the offending connection in config/database.php.","Ensure DB_CONNECTION is set in .env (mysql, pgsql, sqlite, sqlsrv).","Verify the connection name passed to DB::connection() actually exists in config and has a driver.","Clear config cache after editing: php artisan config:clear."],"exampleFix":"// before\n'myconn' => ['host' => env('DB_HOST', '127.0.0.1')],\n\n// after\n'myconn' => [\n    'driver' => env('DB_CONNECTION', 'mysql'),\n    'host'   => env('DB_HOST', '127.0.0.1'),\n],","handlingStrategy":"validation","validationCode":"if (! isset($config['driver'])) {\n    throw new \\InvalidArgumentException(\n        \"Connection config '{$name}' is missing the '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":["Always include a 'driver' key with an env fallback in every connection config.","Validate database config in tests by asserting each connection has a driver.","Run `php artisan config:clear` after editing config files."],"tags":["database","configuration","driver","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}