79212889

Date: 2024-11-21 20:51:15
Score: 0.5
Natty:
Report link

Solved by

  1. Creating a MariaDbGrammar exactly as described in the question (following the instruction on https://carbon.nesbot.com/laravel/

  2. 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);
    }
}
  1. On the AppServiceProvider.php, register the connection with the new Connection class:
public function boot(): void
{
    Connection::resolverFor('mariadb', fn(...$args) => new MariaDbConnection(...$args));
}

Done.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Gear8538