For the complete documentation index, see llms.txt. This page is also available as Markdown.

Database Connection (DBAL Module)

Database connection with DBAL module in Laravel

We can use Ecotone's Laravel integration to reuse Connections that are already defined in your Application.

In "config/database.php" we do have list of available connections in our Laravel Application, for example:

'connections' => [
    'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
    ],
(...)

with this using ServiceContext we may tell Ecotone to use this Connection:

class EcotoneConfiguration
{
    #[ServiceContext]
    public function laravelConnection(): LaravelConnectionReference
    {
        return LaravelConnectionReference::defaultConnection('mysql');
    }
}

Using DSN

If we don't have existing connection defined, we can make use of DSN directly

Last updated

Was this helpful?