original_string: public function scopeForUserWithNewMessages($query, $userId)
      {
          return $query->join('participants', 'threads.id', '=', 'participants.thread_id')
              ->where('participants.user_id', $userId)
              ->where(function ($query) {
                  $query->where('threads.updated_at', '>', $this->getConnection()->raw($this->getConnection()->getTablePrefix() . 'participants.last_read'))
                      ->orWhereNull('participants.last_read');
              })
              ->select('threads.*');
      }
code: public function scopeForUserWithNewMessages($query, $userId)
      {
          return $query->join('participants', 'threads.id', '=', 'participants.thread_id')
              ->where('participants.user_id', $userId)
              ->where(function ($query) {
                  $query->where('threads.updated_at', '>', $this->getConnection()->raw($this->getConnection()->getTablePrefix() . 'participants.last_read'))
                      ->orWhereNull('participants.last_read');
              })
              ->select('threads.*');
      }
code_tokens: public function scopeForUserWithNewMessages ( $ query , $ userId ) { return $ query -> join ( 'participants' , 'threads.id' , '=' , 'participants.thread_id' ) -> where ( 'participants.user_id' , $ userId ) -> where ( function ( $ query ) { $ query -> where ( 'threads.updated_at' , '>' , $ this -> getConnection ( ) -> raw ( $ this -> getConnection ( ) -> getTablePrefix ( ) . 'participants.last_read' ) ) -> orWhereNull ( 'participants.last_read' ) ; } ) -> select ( 'threads.*' ) ; }
docstring: Returns threads with new messages that the user is associated with
  
  @param $query
  @param $userId
  @return mixed
docstring_tokens: Returns threads with new messages that the user is associated with