user = $user; $this->new_notice_count = Notice::where('user_id', $this->user->id)->where('status', 0)->count(); $this->new_message_count = ChatMessage::where('other_user_id', $this->user->id)->where('user_id', '<>', 1)->where('status', 0)->count(); $this->new_assistant_message_count = AssistantUser::where('user_id', $this->user->id)->where('status', 0)->count(); } /** * Get the channels the event should broadcast on. * * @return \Illuminate\Broadcasting\Channel|array */ public function broadcastOn() { if (empty($this->user)) { return; } if (empty($this->user->id)) { return; } return new PrivateChannel('users.'.$this->user->id.'.notices'); } // /** // * 事件的广播名称。 // * // * @return string // */ // public function broadcastAs() // { // return 'notice.server'; // } // /** // * 指定广播数据 // * // * @return array // */ // public function broadcastWith() // { // return [ // 'new_notice_count' => $this->new_notice_count, // 'new_message_count'=> $this->new_message_count, // ]; // } // /** // * Determine if this event should broadcast. // * // * @return bool // */ // public function broadcastWhen() // { // return $this->new_notice_count > 0 || $this->new_notice_count > 0; // } }