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',
)
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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.