src/Serializer.php
protected function serializeRelationship(Model $owner, $relationship = null, RelationshipMetadata $relMeta, AdapterInterface $adapter)
    {
        if ($relMeta->isOne()) {
            if (is_array($relationship)) {
                throw SerializerException::badRequest('Invalid relationship value.');
            }
            $serialized = $this->serializeHasOne($owner, $relationship, $adapter);
        } elseif (is_array($relationship) || null === $relationship) {
            $serialized = $this->serializeHasMany($owner, $relationship, $adapter);
        } else {
            throw SerializerException::badRequest('Invalid relationship value.');
        }

        $ownerMeta = $owner->getMetadata();
        $serialized['links'] = [
            'self'      => $adapter->buildUrl($ownerMeta, $owner->getId(), $relMeta->getKey()),
            'related'   => $adapter->buildUrl($ownerMeta, $owner->getId(), $relMeta->getKey(), true),
        ];
        return $serialized;
    }
protected function serializeRelationship(Model $owner, $relationship = null, RelationshipMetadata $relMeta, AdapterInterface $adapter)
    {
        if ($relMeta->isOne()) {
            if (is_array($relationship)) {
                throw SerializerException::badRequest('Invalid relationship value.');
            }
            $serialized = $this->serializeHasOne($owner, $relationship, $adapter);
        } elseif (is_array($relationship) || null === $relationship) {
            $serialized = $this->serializeHasMany($owner, $relationship, $adapter);
        } else {
            throw SerializerException::badRequest('Invalid relationship value.');
        }

        $ownerMeta = $owner->getMetadata();
        $serialized['links'] = [
            'self'      => $adapter->buildUrl($ownerMeta, $owner->getId(), $relMeta->getKey()),
            'related'   => $adapter->buildUrl($ownerMeta, $owner->getId(), $relMeta->getKey(), true),
        ];
        return $serialized;
    }
protected function serializeRelationship ( Model $ owner , $ relationship = null , RelationshipMetadata $ relMeta , AdapterInterface $ adapter ) { if ( $ relMeta -> isOne ( ) ) { if ( is_array ( $ relationship ) ) { throw SerializerException :: badRequest ( 'Invalid relationship value.' ) ; } $ serialized = $ this -> serializeHasOne ( $ owner , $ relationship , $ adapter ) ; } elseif ( is_array ( $ relationship ) || null === $ relationship ) { $ serialized = $ this -> serializeHasMany ( $ owner , $ relationship , $ adapter ) ; } else { throw SerializerException :: badRequest ( 'Invalid relationship value.' ) ; } $ ownerMeta = $ owner -> getMetadata ( ) ; $ serialized [ 'links' ] = [ 'self' => $ adapter -> buildUrl ( $ ownerMeta , $ owner -> getId ( ) , $ relMeta -> getKey ( ) ) , 'related' => $ adapter -> buildUrl ( $ ownerMeta , $ owner -> getId ( ) , $ relMeta -> getKey ( ) , true ) , ] ; return $ serialized ; }
Serializes a relationship value

@param   Model                       $owner
@param   Model|Model[]|null          $relationship
@param   RelationshipMetadata        $relMeta
@param   AdapterInterface            $adapter
@return  array
Serializes a relationship value