public function common($users)
    {
        if ($users instanceof \Illuminate\Database\Eloquent\Collection) {
            $users = $users->map(function ($user) {
                return $user->getKey();
            });
        }

        return $this->withCount(['users' => function ($query) use ($users) {
            $query->whereIn(Chat::userModelPrimaryKey(), $users);
        }])->get()->filter(function ($conversation, $key) use ($users) {
            return $conversation->users_count == count($users);
        });
    }
public function common($users)
    {
        if ($users instanceof \Illuminate\Database\Eloquent\Collection) {
            $users = $users->map(function ($user) {
                return $user->getKey();
            });
        }

        return $this->withCount(['users' => function ($query) use ($users) {
            $query->whereIn(Chat::userModelPrimaryKey(), $users);
        }])->get()->filter(function ($conversation, $key) use ($users) {
            return $conversation->users_count == count($users);
        });
    }
public function common ( $ users ) { if ( $ users instanceof \ Illuminate \ Database \ Eloquent \ Collection ) { $ users = $ users -> map ( function ( $ user ) { return $ user -> getKey ( ) ; } ) ; } return $ this -> withCount ( [ 'users' => function ( $ query ) use ( $ users ) { $ query -> whereIn ( Chat :: userModelPrimaryKey ( ) , $ users ) ; } ] ) -> get ( ) -> filter ( function ( $ conversation , $ key ) use ( $ users ) { return $ conversation -> users_count == count ( $ users ) ; } ) ; }
Gets conversations that are common for a list of users.

@param \Illuminate\Database\Eloquent\Collection | array $users ids

@return \Illuminate\Database\Eloquent\Collection Conversation
Gets conversations that are common for a list of users .