message->loadMissing('user'); } /** * Get the channels the event should broadcast on. * * @return array */ public function broadcastOn(): array { $channels = [ new PrivateChannel('chat.'.$this->message->conversation_id), ]; $supportId = (int) config('chat.support_user_id'); if ($supportId > 0) { $isSupportConversation = $this->message->conversation() ->whereHas('users', fn ($query) => $query->where('users.id', $supportId)) ->exists(); if ($isSupportConversation) { $channels[] = new PrivateChannel('chat.support'); } } return $channels; } public function broadcastAs(): string { return 'message.sent'; } /** * @return array */ public function broadcastWith(): array { return (new MessageResource($this->message->loadMissing('user')))->resolve(); } }