PHP code example of marcusvbda / filament-realtime-driver

1. Go to this page and download the library: Download marcusvbda/filament-realtime-driver library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

marcusvbda / filament-realtime-driver example snippets


use Marcusvbda\FilamentRealtimeDriver\FilamentRealtimeDriverPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugin(
            FilamentRealtimeDriverPlugin::make()->socket()
        );
}

use Filament\Tables\Table;

public static function table(Table $table): Table
{
    return $table
        ->columns([
            // ...
        ])
        ->socket(
            channel: 'orders',
            event: 'OrderUpdated',
        );
}

use Marcusvbda\FilamentRealtimeDriver\RealtimeEvent;

protected static function booted(): void
{
    static::saved(function (Order $order): void {
        RealtimeEvent::dispatch('orders', 'OrderUpdated', ['id' => $order->id]);
    });
}

use Illuminate\Support\Facades\Auth;

->socket(
    channel: 'jobs_' . Auth::id(),
    event: 'JobUpdated',
)

// App\Models\Job::booted()
static::saved(function (Job $job): void {
    RealtimeEvent::dispatch('jobs_' . Auth::id(), 'JobUpdated', ['id' => $job->id]);
});

use Marcusvbda\FilamentRealtimeDriver\RealtimeConnection;

->plugin(
    FilamentRealtimeDriverPlugin::make()->socket(
        function (RealtimeConnection $listener) {
            $listener->watch('event.example', function ($params) {
                Log::info('Realtime event received', ['params' => $params]);
            });
        }
    )
)

if ($this->app->runningInConsole()) {
    DevCommands::artisan('filament-realtime-driver:listen', 'realtime');
}

->plugin(
    FilamentRealtimeDriverPlugin::make()
        ->socket()
        ->databaseNotifications()
)

   $panel->databaseNotifications();
   

   use Filament\Notifications\Notification;

   Notification::make()
       ->title('Something happened')
       ->body('Details here')
       ->sendToDatabase($user, isEventDispatched: true);
   

use Marcusvbda\FilamentRealtimeDriver\RealtimeEvent;

broadcast(new RealtimeEvent('orders', 'OrderUpdated', ['id' => $order->id]));
// or
RealtimeEvent::dispatch('orders', 'OrderUpdated', ['id' => $order->id]);

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);
});
bash
php artisan reverb:start
bash
php artisan filament-realtime-driver:listen