laravel/framework · error · InvalidArgumentException

Unsupported driver [ ].

Error message

Unsupported driver [{$config['driver']}].

What it means

Thrown by ConnectionFactory::createConnector() in the match expression's default arm. The 'driver' value is present but not one of mysql/mariadb/pgsql/sqlite/sqlsrv, and no custom connector is registered in the container under db.connector.<driver>. The factory will only build connectors for drivers it knows or that were explicitly bound.

Solutions

  1. Correct the driver name: 'mysql', 'mariadb', 'pgsql', 'sqlite', or 'sqlsrv'.
  2. Install/enable the matching PDO extension (e.g. pdo_mysql, pdo_pgsql) and restart PHP.
  3. For a custom driver, bind it before opening the connection: $this->app->bind('db.connector.mydriver', MyConnector::class).
  4. Ensure any third-party database package's service provider is registered in config/app.php.

Example fix

// before
// .env: DB_CONNECTION=myslq

// after
// .env: DB_CONNECTION=mysql
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = ['mysql', 'mariadb', 'pgsql', 'sqlite', 'sqlsrv'];
if (! in_array($config['driver'] ?? null, SUPPORTED, true)
    && ! app()->bound("db.connector.{$config['driver']}")) {
    throw new \InvalidArgumentException('Unsupported DB driver: '.($config['driver'] ?? '(none)'));
}

Type guard

function isSupportedDriver(string $driver): bool {
    return in_array($driver, ['mysql', 'mariadb', 'pgsql', 'sqlite', 'sqlsrv'], true);
}

Prevention

When it happens

Trigger: A config with 'driver' => 'mongo' (or any typo such as 'myslq', 'postgre', 'sqlite3'); using a custom driver without first binding db.connector.<driver> in the container; referencing a driver whose PHP extension (pdo_mysql, pdo_pgsql) is not loaded so it was never registered.

Common situations: Typos in DB_CONNECTION; missing PHP PDO extension causing the driver to be unsupported; attempting to use a package-provided driver before its service provider (which binds the connector) is registered.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/ab7981240e83edfb. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Database/Connectors/ConnectionFactory.php:286

     * @throws \InvalidArgumentException
     */
    public function createConnector(array $config)
    {
        if (! isset($config['driver'])) {
            throw new InvalidArgumentException('A driver must be specified.');
        }

        if ($this->container->bound($key = "db.connector.{$config['driver']}")) {
            return $this->container->make($key);
        }

        return match ($config['driver']) {
            'mysql' => new MySqlConnector,
            'mariadb' => new MariaDbConnector,
            'pgsql' => new PostgresConnector,
            'sqlite' => new SQLiteConnector,
            'sqlsrv' => new SqlServerConnector,
            default => throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]."),
        };
    }

    /**
     * Create a new connection instance.
     *
     * @param  string  $driver
     * @param  \PDO|\Closure  $connection
     * @param  string  $database
     * @param  string  $prefix
     * @param  array  $config
     * @return \Illuminate\Database\Connection
     *
     * @throws \InvalidArgumentException
     */
    protected function createConnection($driver, $connection, $database, $prefix = '', array $config = [])
    {
        if ($resolver = Connection::getResolver($driver)) {

View on GitHub (pinned to e0f6eb3518)