protected function getForeignKeyName()
    {
        if (method_exists($this->relation, 'getQualifiedForeignPivotKeyName')) {
            $method = 'getQualifiedForeignPivotKeyName'; // Laravel 5.5
        } elseif (method_exists($this->relation, 'getQualifiedForeignKeyName')) {
            $method = 'getQualifiedForeignKeyName'; // Laravel 5.4
        } else {
            $method = 'getForeignKey'; // Laravel 5.3
        };

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