コード例 #1
0
 private function createMessage(array $message)
 {
     $thread = Thread::create(['subject' => $message['subject'], 'cate' => isset($message['cate']) ? $message['cate'] : 'Msg', 'to_all' => $this->toAll ? 1 : 0]);
     Message::create(['thread_id' => $thread->id, 'user_id' => $message['senderId'], 'body' => $message['body'], 'link' => $message['link']]);
     // participants
     if (!$this->toAll && count($this->toUsers)) {
         //$toUsers = new Collection($this->toUsers);
         $thread->addParticipants($this->toUsers->pluck('id')->all());
     }
 }
コード例 #2
0
 /**
  * get user`s latest broadcasted message thread id
  * @param $userId
  * @return mixed
  */
 private function getBroadcastLatestId()
 {
     return Cache::rememberForever('messenger:latestid:user:'******'to_all', 1)->latest()->first();
         if (!$latestThread) {
             $latestThread = Thread::where('to_all', 1)->where('created_at', '<', $this->created_at)->latest()->first();
         }
         return $latestThread ? $latestThread->id : 0;
     });
 }