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:
Javier Braña
2026-08-31 12:16:56 +02:00
parent 78d1dbf45a
commit 9222eefdf9
26 changed files with 1192 additions and 44 deletions
+12 -3
View File
@@ -5,9 +5,10 @@ namespace App\Notifications;
use App\Models\Comment;
use App\Models\Task;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Notifications\Notification;
class TaskCommentNotification extends Notification
class TaskCommentNotification extends Notification implements ShouldBroadcast
{
use Queueable;
@@ -15,7 +16,7 @@ class TaskCommentNotification extends Notification
public function via($notifiable): array
{
return ['database'];
return ['database', 'broadcast'];
}
public function toArray($notifiable): array
@@ -28,4 +29,12 @@ class TaskCommentNotification extends Notification
'message' => "Nuevo comentario en '{$this->task->title}' por {$this->comment->user->name}: ".substr($this->comment->body, 0, 100),
];
}
}
public function broadcastOn(): array
{
$userIds = [];
if ($this->task->assigned_to) $userIds[] = $this->task->assigned_to;
if ($this->task->created_by) $userIds[] = $this->task->created_by;
return array_map(fn ($id) => new \Illuminate\Broadcasting\PrivateChannel("user.{$id}"), array_unique($userIds));
}
}