message->loadMissing(['user', 'conversation.channel']); } /** * Get the channels the event should broadcast on. * * @return array */ public function broadcastOn(): array { $channels = [ new PrivateChannel('chat.'.$this->message->conversation_id), ]; $conversation = $this->message->conversation; if ($conversation instanceof Conversation && $conversation->isSupportThread()) { $channels[] = new PrivateChannel('chat.support'); } $channel = $conversation?->channel; if ( $channel && $channel->channelables_type === User::class && $channel->channelables_id ) { $channels[] = new PrivateChannel('chat.inbox.'.$channel->channelables_id); } return $channels; } public function broadcastAs(): string { return 'message.sent'; } /** * @return array */ public function broadcastWith(): array { return (new MessageResource($this->message->loadMissing('user')))->resolve(); } }