/**
  * @param ResourceDefinition|string $resourceDefinition
  * @param mixed $entities
  * @param ContextContract $context
  * @param RelationshipValue $parent
  * @param null $parentEntity
  * @return ResourceCollection
  * @throws InvalidContextAction
  * @throws InvalidEntityException
  */
 public function toResources($resourceDefinition, $entities, ContextContract $context, RelationshipValue $parent = null, $parentEntity = null) : ResourceCollection
 {
     if (!ArrayHelper::isIterable($entities)) {
         throw new InvalidEntityException(__CLASS__ . '::toResources expects an iterable object of entities.');
     }
     $resourceDefinition = ResourceDefinitionLibrary::make($resourceDefinition);
     $out = new ResourceCollection();
     foreach ($entities as $entity) {
         $out->add($this->toResource($resourceDefinition, $entity, $context, $parent, $parentEntity));
     }
     $context->getProcessors()->processCollection($this, $out, $resourceDefinition, $context, $parent, $parentEntity);
     return $out;
 }
Exemplo n.º 2
0
 /**
  * @return mixed
  */
 public function toArray()
 {
     return $this->children->toArray();
 }