/** * Returns all threads with new messages * * @return array */ public function threadsWithNewMessages() { $threadsWithNewMessages = []; $participants = Participant::where('user_id', $this->id)->lists('last_read', 'thread_id'); if ($participants) { $threads = Thread::whereIn('id', array_keys($participants))->get(); foreach ($threads as $thread) { if ($thread->updated_at > $participants[$thread->id]) { $threadsWithNewMessages[] = $thread->id; } } } return $threadsWithNewMessages; }