- 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)
38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\Issue;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class IssueReportedNotification extends Notification implements ShouldBroadcast
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(public Issue $issue) {}
|
|
|
|
public function via($notifiable): array
|
|
{
|
|
return ['database', 'broadcast'];
|
|
}
|
|
|
|
public function toArray($notifiable): array
|
|
{
|
|
return [
|
|
'type' => 'issue_reported',
|
|
'issue_id' => $this->issue->id,
|
|
'project_id' => $this->issue->project_id,
|
|
'feature_name' => $this->issue->feature?->name ?? '—',
|
|
'priority' => $this->issue->priority,
|
|
'message' => "Nuevo issue '{$this->issue->title}' (prioridad: {$this->issue->priority})",
|
|
];
|
|
}
|
|
|
|
public function broadcastOn(): array
|
|
{
|
|
$userIds = $this->issue->project->users->pluck('id')->toArray();
|
|
return array_map(fn ($id) => new \Illuminate\Broadcasting\PrivateChannel("user.{$id}"), $userIds);
|
|
}
|
|
} |