src/Schema/CreatesEloquentIdentities.php
protected function createBelongsToIdentity(Model $model, $relationshipKey)
    {
        $relation = $model->{$relationshipKey}();

        if (!$relation instanceof BelongsTo) {
            throw new RuntimeException(sprintf(
                'Expecting %s on %s to be a belongs-to relationship.',
                $relationshipKey,
                get_class($model)
            ));
        }

        // support Laravel 5.8
        $foreignKey = method_exists($relation, 'getForeignKeyName') ?
            $relation->getForeignKeyName() :
            $relation->getForeignKey();

        $id = $model->{$foreignKey};

        if (is_null($id)) {
            return null;
        }

        // support Laravel 5.8
        $ownerKey = method_exists($relation, 'getOwnerKeyName') ?
            $relation->getOwnerKeyName() :
            $relation->getOwnerKey();

        $related = $relation->getRelated()->replicate();
        $related->{$ownerKey} = $id;

        return $related;
    }
protected function createBelongsToIdentity(Model $model, $relationshipKey)
    {
        $relation = $model->{$relationshipKey}();

        if (!$relation instanceof BelongsTo) {
            throw new RuntimeException(sprintf(
                'Expecting %s on %s to be a belongs-to relationship.',
                $relationshipKey,
                get_class($model)
            ));
        }

        // support Laravel 5.8
        $foreignKey = method_exists($relation, 'getForeignKeyName') ?
            $relation->getForeignKeyName() :
            $relation->getForeignKey();

        $id = $model->{$foreignKey};

        if (is_null($id)) {
            return null;
        }

        // support Laravel 5.8
        $ownerKey = method_exists($relation, 'getOwnerKeyName') ?
            $relation->getOwnerKeyName() :
            $relation->getOwnerKey();

        $related = $relation->getRelated()->replicate();
        $related->{$ownerKey} = $id;

        return $related;
    }
Convert a belongs to relationship without causing the database to be queried.

This should only be used when the related model is not going to be included in the
JSON API response to the client. In those circumstances, it is more efficient than
returning the actual related model because there will be no database query to
obtain the full related model.

@param Model $model
@param $relationshipKey
@return Model
@deprecated