Solved by
Creating a MariaDbGrammar exactly as described in the question (following the instruction on https://carbon.nesbot.com/laravel/
Creating a MariaDbConnection class in my application that extends Illuminate's MariadDbConnection:
class MariaDbConnection extends IlluminateMariaDbConnection
{
protected function getDefaultQueryGrammar(): MariaDbGrammar
{
// this is the Grammar created on the previous step
($grammar = new MariaDbGrammar())->setConnection($this);
return $this->withTablePrefix($grammar);
}
}
AppServiceProvider.php
, register the connection with the new Connection class:public function boot(): void
{
Connection::resolverFor('mariadb', fn(...$args) => new MariaDbConnection(...$args));
}
Done.