public function userUnreadMessages($userId)
    {
        $messages = $this->messages()->get();

        try {
            $participant = $this->getParticipantFromUser($userId);
        } catch (ModelNotFoundException $e) {
            return collect();
        }

        if (!$participant->last_read) {
            return $messages;
        }

        return $messages->filter(function ($message) use ($participant) {
            return $message->updated_at->gt($participant->last_read);
        });
    }
public function userUnreadMessages($userId)
    {
        $messages = $this->messages()->get();

        try {
            $participant = $this->getParticipantFromUser($userId);
        } catch (ModelNotFoundException $e) {
            return collect();
        }

        if (!$participant->last_read) {
            return $messages;
        }

        return $messages->filter(function ($message) use ($participant) {
            return $message->updated_at->gt($participant->last_read);
        });
    }
public function userUnreadMessages ( $ userId ) { $ messages = $ this -> messages ( ) -> get ( ) ; try { $ participant = $ this -> getParticipantFromUser ( $ userId ) ; } catch ( ModelNotFoundException $ e ) { return collect ( ) ; } if ( ! $ participant -> last_read ) { return $ messages ; } return $ messages -> filter ( function ( $ message ) use ( $ participant ) { return $ message -> updated_at -> gt ( $ participant -> last_read ) ; } ) ; }
Returns array of unread messages in thread for given user.

@param int $userId

@return \Illuminate\Support\Collection
Returns array of unread messages in thread for given user .