data = $data; $this->notifiable = $notifiable; $this->notification = $notification; } /** * Get the channels the event should broadcast on. * * @return array */ public function broadcastOn() { $channels = $this->notification->broadcastOn(); if (! empty($channels)) { return $channels; } return [new PrivateChannel($this->channelName())]; } /** * Get the data that should be sent with the broadcasted event. * * @return array */ public function broadcastWith() { return array_merge($this->data, [ 'id' => $this->notification->id, 'type' => get_class($this->notification), ]); } /** * Get the broadcast channel name for the event. * * @return string */ protected function channelName() { if (method_exists($this->notifiable, 'receivesBroadcastNotificationsOn')) { return $this->notifiable->receivesBroadcastNotificationsOn($this->notification); } $class = str_replace('\\', '.', get_class($this->notifiable)); return $class.'.'.$this->notifiable->getKey(); } }