← Docs

Laravel + Eloquent

Service provider that proxies all PostgreSQL connections automatically. Auto-discovered by Laravel — zero config required. Eloquent, the query builder, and migrations all route through Gold Lapel transparently.

Install

composer require goldlapel/goldlapel

Laravel's package auto-discovery (5.5+) registers GoldLapel\Laravel\GoldLapelServiceProvider automatically. No manual provider registration or config publishing needed.

Usage

All PostgreSQL connections are proxied automatically. The L1 native cache activates automatically — repeated reads serve in microseconds. Every Eloquent model, query builder call, relationship eager-load, and artisan migrate run flows through Gold Lapel unchanged. Add a goldlapel key to your connection in config/database.php to customise settings or disable for a specific connection:

// config/database.php
'pgsql' => [
    'driver' => 'pgsql',
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '5432'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'goldlapel' => [
        'enabled' => true,
        'port' => 7932,
        'config' => [
            'mode' => 'waiter',
            'pool_size' => 50,
        ],
        'extra_args' => [],
    ],
],

Configuration

KeyDefaultDescription
goldlapel.enabledtrueSet to false to disable for this connection
goldlapel.port7932Local proxy port
goldlapel.config[]Full Gold Lapel config array (same keys as GoldLapel::start($url, config: ...))
goldlapel.extra_args[]Extra CLI args passed to the Gold Lapel binary

The config array takes the same keys as GoldLapel::start($url, config: ...) — see the configuration reference for every setting.

Multiple Databases

Each proxied connection needs its own port. Assign a unique goldlapel.port to each connection:

'primary' => [
    'driver' => 'pgsql',
    'host' => 'db1.example.com',
    'goldlapel' => ['port' => 7932],
],
'analytics' => [
    'driver' => 'pgsql',
    'host' => 'db2.example.com',
    'goldlapel' => ['port' => 7942],
],

Laravel's tenancy packages, read replica connections (read / write arrays), and custom connection resolvers all continue to work — each connection gets its own Gold Lapel instance.

Advanced Tuning

Use extra_args to pass any Gold Lapel CLI flag directly to the proxy process, or drop settings into the config array. You can also set GOLDLAPEL_* environment variables for configuration that varies between environments.

Requirements

  • PHP 8.1+
  • Laravel 10+
  • goldlapel/goldlapel 0.2+
  • PostgreSQL (TCP connections only)

Upgrading from v0.1

The Laravel integration is unchanged at the surface — Composer require, existing config/database.php keys work unchanged. The v0.2 changes are internal: the service provider now calls GoldLapel::startProxyOnly($url, $options) (a URL-only variant, because Laravel manages its own PDOs via its Connection resolver).

// v0.1.x (old) — same install, same config
composer require goldlapel/goldlapel

// v0.2 (new) — identical from Laravel's perspective
composer require goldlapel/goldlapel
// Internally the service provider now calls GoldLapel::startProxyOnly()
  • Install command unchanged — composer require goldlapel/goldlapel.
  • Service provider is still auto-discovered — namespace: GoldLapel\Laravel\GoldLapelServiceProvider.
  • config/database.php goldlapel keys unchanged — existing enabled / port / extra_args still work. config is the newly exposed full-config passthrough.
  • If you also use GoldLapel::start directly outside Laravel, see the PHP guide for the v0.2 factory shape.

How It Works

The service provider runs at boot. For each PostgreSQL connection with Gold Lapel enabled, it:

  1. Builds the upstream database URL from your connection config
  2. Calls GoldLapel::startProxyOnly() — Laravel owns its own PDO pool, so only the proxy is spawned
  3. Rewrites the connection's host/port to the local proxy and registers a custom Connection resolver that wraps the PDO with the L1 native cache

Eloquent, the query builder, Artisan commands, and raw DB:: calls all route through the wrapped connection automatically.