public function collect(Resource $resource) { $serializer = $resource->getSerializer(); $collections = new ProcessingCollections($serializer->getName(), $this->registry->resolveNestedSerializers($serializer)); // Load direct children of the resource into collections if ($resource instanceof ResourceCollection) { foreach ($resource as $item) { $collections->process($serializer, $item); } } else { $collections->process($serializer, $resource->unwrap()); } $collections->processNested(); return $collections->toResourceCollections(); }