Download the PHP package splitstack/translucid without Composer
On this page you can find all versions of the php package splitstack/translucid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download splitstack/translucid
More information about splitstack/translucid
Files in splitstack/translucid
Package translucid
Short Description Realtime model updates for Laravel via Postgres LISTEN/NOTIFY or Eloquent lifecycle events
License MIT
Informations about the package translucid
Translucid
Real-time model change broadcasting for Laravel — powered by PostgreSQL LISTEN/NOTIFY or Eloquent lifecycle events.
When a row changes in your database, Translucid fires a Laravel broadcast event on a private channel. Your frontend can subscribe and react instantly, without polling.
Requirements
- PHP 8.2+
- Laravel 11, 12, or 13
- PostgreSQL (required for the DB-mode listener)
laravel/pennant^1.0
Installation
Publish the config:
How it works
Translucid supports two broadcast sources — you pick one (or both) per scope via Pennant feature flags:
| Mode | How events are triggered |
|---|---|
From DB (TranslucidFromDB) |
PostgreSQL triggers call pg_notify. A long-running translucid:listen command picks them up and dispatches broadcast events. |
From App (TranslucidFromApp) |
The HasTranslucid trait adds Eloquent observers (created, updated, deleted) that dispatch broadcast events inline. |
Both modes emit the same three events: TranslucidCreated, TranslucidUpdated, TranslucidDeleted.
Getting started
1. Install database triggers (DB mode)
Create a migration to register PostgreSQL triggers for each model you want to observe:
Run migrations, then start the listener:
2. Add the trait (App mode)
Add HasTranslucid to any Eloquent model to broadcast changes via Eloquent observers instead:
3. Activate a feature flag
Both modes are gated by Pennant. Activate the flag for the scope you want (a user, tenant, or null for global):
Broadcast payload
Events broadcast on a private channel (default: translucid). Each event carries:
The broadcast event name includes the table and record key:
Configuration
config/translucid.php:
Multi-tenancy
Built-in Spatie driver
If you use spatie/laravel-multitenancy, configure the built-in driver:
The listener will open a separate PostgreSQL LISTEN connection per tenant and broadcast on scoped channels like translucid.acme.
Custom driver
Implement the TenantDriver contract to integrate any tenancy strategy:
Register it in config/translucid.php:
Custom channel resolver (without a driver)
For simple cases you can override the channel resolver directly in a service provider:
Artisan commands
| Command | Description |
|---|---|
php artisan translucid:listen |
Start polling PostgreSQL for notifications and dispatching broadcast events. Handles SIGINT/SIGTERM for graceful shutdown. |
Events reference
| Event | Broadcast name | op value |
|---|---|---|
TranslucidCreated |
translucid.created.{table}.{id} |
created |
TranslucidUpdated |
translucid.updated.{table}.{id} |
updated |
TranslucidDeleted |
translucid.deleted.{table}.{id} |
deleted |
All three are standard Laravel broadcastable events and work with any broadcasting driver (Reverb, Pusher, Ably, etc.).
Testing
License
MIT — see LICENSE.md.