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,10 +4,11 @@ namespace App\Notifications;
|
||||
|
||||
use App\Models\IssueComment;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class IssueCommentedNotification extends Notification
|
||||
class IssueCommentedNotification extends Notification implements ShouldBroadcast
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
@@ -15,7 +16,7 @@ class IssueCommentedNotification extends Notification
|
||||
|
||||
public function via($notifiable): array
|
||||
{
|
||||
return ['database'];
|
||||
return ['database', 'broadcast'];
|
||||
}
|
||||
|
||||
public function toArray($notifiable): array
|
||||
@@ -30,4 +31,13 @@ class IssueCommentedNotification extends Notification
|
||||
'message' => "{$this->comment->user?->name} comentó en '{$issue?->title}': ".Str::limit($this->comment->body, 60),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
$issue = $this->comment->issue;
|
||||
$userIds = [];
|
||||
if ($issue->assigned_to) $userIds[] = $issue->assigned_to;
|
||||
if ($issue->reported_by) $userIds[] = $issue->reported_by;
|
||||
return array_map(fn ($id) => new \Illuminate\Broadcasting\PrivateChannel("user.{$id}"), array_unique($userIds));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user