src/Models/CmsModel.php
public function getBelongsToRelationAttributeValue($key)
    {
        $relationKey  = camel_case($key);
        $attributeKey = snake_case($key);

        if ($this->relationLoaded($relationKey)) {

            // check to make sure we don't break eager loading and internal
            // lookups for the foreign key
            $self = __FUNCTION__;

            $caller = array_first(debug_backtrace(false), function ($key, $trace) use ($self) {
                $caller = $trace['function'];

                // skip first two (since that includes the Model's generated method)
                if ($key < 2) {
                    return false;
                }

                if (array_get($trace, 'class') === 'Illuminate\Database\Eloquent\Relations\BelongsTo') {
                    return false;
                }

                return $caller != $self
                    && $caller != 'mutateAttribute'
                    && $caller != 'getAttributeValue'
                    && $caller != 'getAttribute'
                    && $caller != '__get';
            });

            if (    ! array_key_exists('class', $caller)
                ||  (   $caller['class'] !== 'Illuminate\Database\Eloquent\Model'
                    &&  $caller['class'] !== 'Illuminate\Database\Eloquent\Builder'
                    &&  $caller['class'] !== 'Illuminate\Database\Eloquent\Relations\Relation'
                    )
            ) {
                return $this->relations[$relationKey];
            }
        }

        return $this->attributes[$attributeKey];
    }
public function getBelongsToRelationAttributeValue($key)
    {
        $relationKey  = camel_case($key);
        $attributeKey = snake_case($key);

        if ($this->relationLoaded($relationKey)) {

            // check to make sure we don't break eager loading and internal
            // lookups for the foreign key
            $self = __FUNCTION__;

            $caller = array_first(debug_backtrace(false), function ($key, $trace) use ($self) {
                $caller = $trace['function'];

                // skip first two (since that includes the Model's generated method)
                if ($key < 2) {
                    return false;
                }

                if (array_get($trace, 'class') === 'Illuminate\Database\Eloquent\Relations\BelongsTo') {
                    return false;
                }

                return $caller != $self
                    && $caller != 'mutateAttribute'
                    && $caller != 'getAttributeValue'
                    && $caller != 'getAttribute'
                    && $caller != '__get';
            });

            if (    ! array_key_exists('class', $caller)
                ||  (   $caller['class'] !== 'Illuminate\Database\Eloquent\Model'
                    &&  $caller['class'] !== 'Illuminate\Database\Eloquent\Builder'
                    &&  $caller['class'] !== 'Illuminate\Database\Eloquent\Relations\Relation'
                    )
            ) {
                return $this->relations[$relationKey];
            }
        }

        return $this->attributes[$attributeKey];
    }
public function getBelongsToRelationAttributeValue ( $ key ) { $ relationKey = camel_case ( $ key ) ; $ attributeKey = snake_case ( $ key ) ; if ( $ this -> relationLoaded ( $ relationKey ) ) { // check to make sure we don't break eager loading and internal // lookups for the foreign key $ self = __FUNCTION__ ; $ caller = array_first ( debug_backtrace ( false ) , function ( $ key , $ trace ) use ( $ self ) { $ caller = $ trace [ 'function' ] ; // skip first two (since that includes the Model's generated method) if ( $ key < 2 ) { return false ; } if ( array_get ( $ trace , 'class' ) === 'Illuminate\Database\Eloquent\Relations\BelongsTo' ) { return false ; } return $ caller != $ self && $ caller != 'mutateAttribute' && $ caller != 'getAttributeValue' && $ caller != 'getAttribute' && $ caller != '__get' ; } ) ; if ( ! array_key_exists ( 'class' , $ caller ) || ( $ caller [ 'class' ] !== 'Illuminate\Database\Eloquent\Model' && $ caller [ 'class' ] !== 'Illuminate\Database\Eloquent\Builder' && $ caller [ 'class' ] !== 'Illuminate\Database\Eloquent\Relations\Relation' ) ) { return $ this -> relations [ $ relationKey ] ; } } return $ this -> attributes [ $ attributeKey ] ; }
Returns value for either foreign key or eager loaded contents of relation,
depending on what is expected

This should not break calls to the belongsTo relation method, including after
using the load() method to eager load the relation's contents

@param string $key
@return mixed
Returns value for either foreign key or eager loaded contents of relation depending on what is expected