Sitemap

Error: Method Illuminate\Database\MySqlConnection::getDoctrineConnection does not exist with Laravel 11

Apr 3, 2025

--

Here to fix we install

composer require doctrine/dbal

Also added in boot() method at AppServiceProvider.php the code below:

if (Config::get('database.default') === 'mysql'
&& !Connection::hasMacro('getDoctrineConnection')) {
Connection::macro('getDoctrineConnection', function () {
return DriverManager::getConnection([
'pdo' => $this->getPdo(),
'dbname' => $this->getDatabaseName(),
'driver' => 'pdo_mysql',
'user' => Config::get('database.connections.mysql.username'),
'password' => Config::get('database.connections.mysql.password'),
'host' => Config::get('database.connections.mysql.host'),
'port' => Config::get('database.connections.mysql.port'),
'charset' => Config::get('database.connections.mysql.charset', 'utf8mb4'),
]);
});
}

I hope this helps anyone that have it.

--

--

No responses yet