data = $data; } /** * Get the channels the event should broadcast on. * * @return Channel|array */ public function broadcastOn() { return new \Illuminate\Broadcasting\Channel($this->channelName()); } /** * Get the data to broadcast. * * @return array */ public function broadcastWith() { return $this->data; } /** * Get the broadcast channel name for the event. * * @return string */ protected function channelName() { if (!empty($this->data['mailbox_id'])) { return 'mailbox.'.$this->data['mailbox_id']; } else { return 'mailbox.0'; } } /** * Helper funciton. */ public static function dispatchSelf($mailbox_id) { $notification_data = [ 'mailbox_id' => $mailbox_id ]; event(new \App\Events\RealtimeMailboxNewThread($notification_data)); } public static function processPayload($payload) { $user = auth()->user(); $mailbox = Mailbox::rememberForever()->find($payload->mailbox_id); // Check if user can listen to this event. if (!$user || !$mailbox || !$user->can('viewCached', $mailbox)) { return []; } $folder = null; $foler_id = Conversation::getFolderParam(); if ($foler_id) { $folder = Folder::find($foler_id); } // Just in case. if (!$folder) { $folder = new Folder(); } $template_data = [ 'folders' => $mailbox->getAssesibleFolders(), 'folder' => $folder, 'mailbox' => $mailbox, ]; $payload->folders_html = \View::make('mailboxes/partials/folders')->with($template_data)->render(); return $payload; } }