protected function getRelatedKeyName()
    {
        if (method_exists($this->relation, 'getQualifiedRelatedPivotKeyName')) {
            $method = 'getQualifiedRelatedPivotKeyName'; // Laravel 5.5
        } elseif (method_exists($this->relation, 'getQualifiedRelatedKeyName')) {
            $method = 'getQualifiedRelatedKeyName'; // Laravel 5.4
        } else {
            $method = 'getOtherKey'; // Laravel 5.3
        };

        return last(explode('.', $this->relation->$method()));
    }