protected function getRelatedPivotKeyName(BelongsToMany $relation)
    {
        if (method_exists($relation, 'getRelatedPivotKeyName')) {
            return $relation->getRelatedPivotKeyName();
        }

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

        return $relation->getOtherKey();
    }