/** * Get an array of built relationships. * * @return \Tobscure\JsonApi\Relationship[] */ protected function buildRelationships() { if (isset($this->relationships)) { return $this->relationships; } $paths = Util::parseRelationshipPaths($this->includes); $relationships = []; foreach ($paths as $name => $nested) { $relationship = $this->serializer->getRelationship($this->data, $name); if ($relationship) { $relationshipData = $relationship->getData(); if ($relationshipData instanceof ElementInterface) { $relationshipData->with($nested)->fields($this->fields); } $relationships[$name] = $relationship; } } return $this->relationships = $relationships; }
/** * Serialize the data as appropriate. * * @param SerializerInterface $serializer * @param array $data * @return \Tobscure\JsonApi\Elements\Collection */ protected function serialize(SerializerInterface $serializer, $data) { return $serializer->collection($data); }
/** * Serialize the data as appropriate. * * @param \Tobscure\JsonApi\SerializerInterface $serializer * @param array $data * @return \Tobscure\JsonApi\Elements\Resource */ protected function serialize(SerializerInterface $serializer, $data) { return $serializer->resource($data); }