public function scopeBetween($query, array $participants)
    {
        $query->whereHas('participants', function ($query) use ($participants) {
            $query->whereIn('user_id', $participants)
                    ->groupBy('thread_id')
                    ->havingRaw('COUNT(thread_id)='.count($participants));
        });
    }
public function scopeBetween($query, array $participants)
    {
        $query->whereHas('participants', function ($query) use ($participants) {
            $query->whereIn('user_id', $participants)
                    ->groupBy('thread_id')
                    ->havingRaw('COUNT(thread_id)='.count($participants));
        });
    }
public function scopeBetween ( $ query , array $ participants ) { $ query -> whereHas ( 'participants' , function ( $ query ) use ( $ participants ) { $ query -> whereIn ( 'user_id' , $ participants ) -> groupBy ( 'thread_id' ) -> havingRaw ( 'COUNT(thread_id)=' . count ( $ participants ) ) ; } ) ; }
Returns threads between given user ids

@param $query
@param $participants
@return mixed
Returns threads between given user ids