notification = $notification; } /** * Get the channels the event should broadcast on. * * @return array */ public function broadcastOn(): array { $recipient = $this->notification->recipient; // 1. GLOBAL / PUBLIC if ($recipient === 'all') { return [new Channel('notifications')]; } // 2. SPECIFIC USER (ID is numeric) if (is_numeric($recipient)) { return [new PrivateChannel('App.Models.User.'.$recipient)]; } // 3. BY ROLE (Default fallback for strings like 'admin', 'superadmin', 'user', etc.) return [new PrivateChannel('roles.'.$recipient)]; } /** * The event's broadcast name. */ public function broadcastAs(): string { return 'notification.sent'; } }