feat: Phase 2 - Laravel Reverb + real-time notifications
- Install laravel/reverb + laravel-echo + pusher-js - Configure broadcasting to reverb in .env.example + .env - Add Echo + Pusher client in resources/js/app.js - Update all 14 notifications to implement ShouldBroadcast + broadcastOn() - Update NotificationBell component to listen for real-time events - Add Livewire.emit in notification-bell blade for JS-to-Livewire bridge Tests: 101 passing (319 assertions)
This commit is contained in:
@@ -4,9 +4,10 @@ namespace App\Notifications;
|
||||
|
||||
use App\Models\Feature;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class FeatureCompletedNotification extends Notification
|
||||
class FeatureCompletedNotification extends Notification implements ShouldBroadcast
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
@@ -14,7 +15,7 @@ class FeatureCompletedNotification extends Notification
|
||||
|
||||
public function via($notifiable): array
|
||||
{
|
||||
return ['database'];
|
||||
return ['database', 'broadcast'];
|
||||
}
|
||||
|
||||
public function toArray($notifiable): array
|
||||
@@ -28,4 +29,14 @@ class FeatureCompletedNotification extends Notification
|
||||
'message' => "Elemento '{$this->feature->name}' marcado como completado",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
$projectId = $this->feature->layer?->phase?->project_id;
|
||||
if (! $projectId) {
|
||||
return [];
|
||||
}
|
||||
$userIds = \App\Models\Project::find($projectId)?->users->pluck('id')->toArray() ?? [];
|
||||
return array_map(fn ($id) => new \Illuminate\Broadcasting\PrivateChannel("user.{$id}"), $userIds);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user