user = $user; $this->message = $message; $new_notice_count = Notice::where('user_id', $user->id)->where('status', 0)->count(); if (empty($new_notice_count)) { $new_notice_count = 0; } $new_message_count = ChatMessage::where('other_user_id', $user->id)->where('status', 0)->count(); if (empty($new_message_count)) { $new_message_count = 0; } $this->new_notice_count = $new_notice_count; $this->new_message_count = $new_message_count; } /** * Get the channels the event should broadcast on. * * @return \Illuminate\Broadcasting\Channel|array */ public function broadcastOn() { if (empty($this->user)) { return; } return new PrivateChannel('users.'.$this->user->id.'.chat.message'); } // /** // * 事件的广播名称。 // * // * @return string // */ // public function broadcastAs() // { // return 'chat.message'; // } }