### Install Laravel Reverb Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Installs Laravel Reverb and runs the installer, which publishes config/reverb.php, adds REVERB_* and VITE_REVERB_* variables to .env, and sets BROADCAST_CONNECTION=reverb. ```bash composer require laravel/reverb php artisan reverb:install ``` -------------------------------- ### Start Reverb Server Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Starts the Reverb server locally. Optionally add it to composer.json dev script via DevCommands::artisan('reverb:start', 'reverb') so composer dev starts it alongside everything else. ```bash php artisan reverb:start ``` -------------------------------- ### Install via local path repository in composer.json Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Install the package as a local path repository by adding the repository and require entries to composer.json, then run composer update. The service provider is auto-discovered, so no manual registration is needed. ```json { "repositories": [ { "type": "path", "url": "packages/filament-realtime-driver" } ], "require": { "recruiter-labs/filament-realtime-driver": "*" } } ``` ```bash composer update recruiter-labs/filament-realtime-driver ``` -------------------------------- ### Wire listener into composer dev in AppServiceProvider Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Wire the listener into `composer dev` in `AppServiceProvider::boot()` the same way you would `reverb:start` or a queue worker. Only runs in console context. ```php if ($this->app->runningInConsole()) { DevCommands::artisan('filament-realtime-driver:listen', 'realtime'); } ``` -------------------------------- ### Run Artisan command filament-realtime-driver:listen Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Run the bundled Artisan command to start the long-lived, blocking listener process. This is not meant to be called from an HTTP request. ```bash php artisan filament-realtime-driver:listen ``` -------------------------------- ### Send notification with isEventDispatched: true Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Send a database notification with `isEventDispatched: true` so that the broadcast event is dispatched. Without this flag, nothing gets broadcast. ```php use Filament\Notifications\Notification; Notification::make() ->title('Something happened') ->body('Details here') ->sendToDatabase($user, isEventDispatched: true); ``` -------------------------------- ### Segment channel per user with Auth::id() Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Parametrize the channel name with a per-user identifier to scope who receives the update. This example uses `Auth::id()` so the browser subscribes to `jobs_{theViewer'sOwnId}`. ```php use Illuminate\Support\Facades\Auth; ->socket( channel: 'jobs_' . Auth::id(), event: 'JobUpdated', ) ``` -------------------------------- ### Use Table::socket() in a Filament table Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Adds a `socket()` method to `Filament\Tables\Table` as an alternative to `->poll(...)`. The table subscribes once over the shared socket; when the exact channel/event pair is received, the table's Livewire component gets `$wire.$refresh()`'d. Requires the panel's plugin to have `->socket()` enabled; otherwise the injected listener no-ops safely. ```php use Filament\Tables\Table; public static function table(Table $table): Table { return $table ->columns([ // ... ]) ->socket( channel: 'orders', event: 'OrderUpdated', ); } ``` -------------------------------- ### Register FilamentRealtimeDriverPlugin with ->socket() Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Register the plugin on a Filament panel and call ->socket() to make the shared browser client available. This alone doesn't change visible behavior; you must opt into individual features separately. ```php use Marcusvbda\FilamentRealtimeDriver\FilamentRealtimeDriverPlugin; public function panel(Panel $panel): Panel { return $panel // ... ->plugin( FilamentRealtimeDriverPlugin::make()->socket() ); } ``` -------------------------------- ### Configure persistent PHP listener with ->socket() Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Configure a persistent PHP listener for realtime events by passing a callback to `->socket()`. The callback receives a `RealtimeConnection` instance and uses `watch()` to subscribe to an event. This is for server-side reactions independent of any browser. ```php use Marcusvbda\FilamentRealtimeDriver\RealtimeConnection; ->plugin( FilamentRealtimeDriverPlugin::make()->socket( function (RealtimeConnection $listener) { $listener->watch('event.example', function ($params) { Log::info('Realtime event received', ['params' => $params]); }); } ) ) ``` -------------------------------- ### Enable database notifications with ->databaseNotifications() Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Enable database notifications with push updates by calling `->databaseNotifications()` on the plugin. This replaces Filament's polling with a push using the broadcast event Filament already ships. ```php ->plugin( FilamentRealtimeDriverPlugin::make() ->socket() ->databaseNotifications() ) ``` -------------------------------- ### Publish config file with artisan vendor:publish Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Optionally publish the package's config file using the given tag. This is not required for basic functionality. ```bash php artisan vendor:publish --tag=filament-realtime-driver-config ``` -------------------------------- ### Enable Filament's databaseNotifications() on panel Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Enable Filament's own database notifications toggle for the bell UI. This is unrelated to the package and must be enabled separately for the notifications UI to exist. ```php $panel->databaseNotifications(); ``` -------------------------------- ### Use the component Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Place this Blade component anywhere in a view to subscribe to a realtime event. Inside the slot, `event` is an Alpine-reactive object holding whatever `broadcastWith()` sent; bind to it with `x-text`, `x-show`, etc. Works on any page and does not require Livewire. ```blade

@script @endscript
``` -------------------------------- ### Authorize private channels in routes/channels.php Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Define authorization rules for private/presence channels in routes/channels.php. Required for Filament's database notifications and for your own private channels. Public channels need no entry. ```php use Illuminate\Support\Facades\Broadcast; // Required for Filament's own database notifications feature — publish it // via `php artisan reverb:install` / `php artisan install:broadcasting`, // or add it yourself if it's missing: Broadcast::channel('App.Models.User.{id}', function ($user, $id) { return (int) $user->id === (int) $id; }); // Your own private channels need the same treatment: Broadcast::channel('orders.{id}', function ($user, $id) { return $user->companies->contains('id', Order::find($id)?->company_id); }); ``` -------------------------------- ### Dispatch to per-user channel with Auth::id() Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Dispatch to a per-user channel using `Auth::id()` on the editor's side. With `Auth::id()` on both sides, a user only sees a live refresh for edits they themselves triggered. This is a public channel (no `private-` prefix) and is not an authorization boundary. ```php // App\Models\Job::booted() static::saved(function (Job $job): void { RealtimeEvent::dispatch('jobs_' . Auth::id(), 'JobUpdated', ['id' => $job->id]); }); ``` -------------------------------- ### Dispatch RealtimeEvent from a model event Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Fire the matching event from wherever the record changes, typically a model event. Dispatches a `RealtimeEvent` with the channel, event name, and payload. ```php use Marcusvbda\FilamentRealtimeDriver\RealtimeEvent; protected static function booted(): void { static::saved(function (Order $order): void { RealtimeEvent::dispatch('orders', 'OrderUpdated', ['id' => $order->id]); }); } ``` -------------------------------- ### Broadcast generic RealtimeEvent Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Dispatch a generic RealtimeEvent with a channel, event name, and payload. It implements ShouldBroadcastNow, so it broadcasts immediately without a queue worker. Use a custom Event class if you need queued broadcasting or richer payload logic. ```php use Marcusvbda\FilamentRealtimeDriver\RealtimeEvent; broadcast(new RealtimeEvent('orders', 'OrderUpdated', ['id' => $order->id])); // or RealtimeEvent::dispatch('orders', 'OrderUpdated', ['id' => $order->id]); ``` -------------------------------- ### Trigger Livewire refresh with callback prop Source: https://github.com/marcusvbda/filament-realtime-driver/blob/master/README.md Use this self-closing variant to trigger a Livewire refresh instead of reading the payload. The `callback` prop is raw JS evaluated every time an event arrives, alongside updating the reactive `event` variable. ```blade ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.