protected function getRelationKeyNames(MorphToMany $relation)
    {
        // We need to get the keys of both tables from the relation class.
        // The method names have changed in Laravel 5.4 & again in 5.5,
        // so we will first check which methods are available to us.
        if (method_exists($relation, 'getForeignKey')) {
            return [
                $relation->getForeignKey(),
                $relation->getOtherKey(),
            ];
        }

        if (method_exists($relation, 'getQualifiedForeignKeyName')) {
            return [
                $relation->getQualifiedForeignKeyName(),
                $relation->getQualifiedRelatedKeyName(),
            ];
        }

        return [
            $relation->getQualifiedForeignPivotKeyName(),
            $relation->getQualifiedRelatedPivotKeyName(),
        ];
    }