Format an Eloquent collection.

@param \Illuminate\Database\Eloquent\Collection $collection

@return string
545889
public function formatEloquentCollection($collection)
    {
        if ($collection->isEmpty()) {
            return $this->encode([]);
        }

        $model = $collection->first();
        $key = Str::plural($model->getTable());

        if (! $model::$snakeAttributes) {
            $key = Str::camel($key);
        }

        return $this->encode([$key => $collection->toArray()]);
    }
6793
public function transform($collection)
    {
        if (null === $collection) {
            return null;
        }

        if (!($collection instanceof Collection)) {
            throw new UnexpectedTypeException($collection, 'Doctrine\Common\Collection\Collection');
        }

        $results = array();
        foreach ($collection as $entity) {
            $results[] = array(
                $this->arrayIdentifierName => $this->displayValue(
                    $this->accessor->getValue($entity, $this->identifier)
                ),
                $this->arrayLabelName => $this->displayValue($this->extractLabel($entity)),
            );
        }

        //Here, do not put the result in the cache because we must check the value in
        //reverseTransform (by QueryBuilder)
        return json_encode($results);
    }
1185325
public static function toMap($collection) {
		$map = new Map();
		foreach ($collection as $k => $v) {
			$map->set($k, self::toCollection($v));
		}

		return $map;
	}
260938
protected function filterCurrentItems(Collection $collection)
    {
        $endDate    = new DateTime();
        $format     = $this->configuration->getGroupByDateFormat();
        $identifier = $endDate->format($format);

        return $collection->filter(function (ReportRow $row) use ($identifier) {
            return $row->getIdentifier() === $identifier;
        });
    }
6615
private function formatCommaSeparated($collection, $count)
    {
        $display = \array_map(function ($element) {
            return (string) $element;
        }, \array_slice($collection, 0, $count - 1));

        return $this->translator->trans('comma_separated', [
            '%list%' => \implode(', ', $display),
            '%last%' => (string) \end($collection),
        ], $this->catalogue);
    }
245516
protected function addPreview(Collection $collection)
    {
        return $collection->setPreview(
            $this->getPreview($collection->getId(), $collection->getLocale())
        );
    }
1224695
public function collection(Collection $collection)
    {
        $entries = new Entries();

        foreach ($collection as $category) {
            $entry = new Entry($category);

            $entry
                ->field('id')
                ->field('label')
                ->field('slug')
                ->field('parent')
                ->field('position')
            ;

            $entries->addEntry($entry);
        }

        return $entries->toArray();
    }
1111526
public function values($collection=null) {
    list($collection) = self::_wrapArgs(func_get_args(), 1);
    
    return self::_wrap(array_values((array) $collection));
  }
207403
public function getTree(\Illuminate\Database\Eloquent\Collection $collection)
    {
        $collection = $collection->sortBy($this->repository->getOrderField());

        return $collection;
    }
717861
protected function methodToAction($method, $collection = false)
    {
        if ($method == 'GET' && $collection) {
            $method = $method . '-collection';
        }
        return isset($this->methodToAction[$method]) ? $this->methodToAction[$method] : $this->defaultAction;
    }
406299
public function javascripts(string $collection, ?string $format = null) : string {
        return $this->serve($collection, 'javascripts', $format);
    }
348378
private function _collection($collection) {
    return (!is_array($collection) && !is_object($collection)) ? str_split((string) $collection) : $collection;
  }
696312
protected function serveProductionCollection(Collection $collection, string $group, ?string $format) : string {
        $entry = $this->getCollectionEntry($collection);

        $fingerprint = $entry->getProductionFingerprint($group);

        $production = $this->{'create'.studly_case($group).'Element'}($this->prefixBuildPath($fingerprint), $format);

        return $this->formatResponse($this->serveRawAssets($collection, $group, $format), $production);
    }
635867
private function getCollectionInfoHtml(&$collection) {
    $previousLink = $collection->getPreviousLink()
                    ? $collection->getPreviousLink() : 'none';

    $nextLink = $collection->getNextLink()
                ? $collection->getNextLink() : 'none';

    return <<<HTML
<pre>
Username       = {$collection->getUsername()}
Items Per Page = {$collection->getItemsPerPage()}
Total Results  = {$collection->getTotalResults()}
Start Index    = {$collection->getStartIndex()}
Previous Link  = {$previousLink}
Next Link      = {$nextLink}
</pre>
HTML;
  }
471240
public function loadCollectionQueryData(Collection $collection): array
    {
        $query = $this->getQuerySelectQuery();
        $query->where(
            $query->expr()->eq('q.collection_id', ':collection_id')
        )
        ->setParameter('collection_id', $collection->id, Type::INTEGER);

        $this->applyStatusCondition($query, $collection->status, 'q.status');

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
314930
protected function composeCollectionLogName($collection)
    {
        if (is_array($collection)) {
            list($database, $collection) = $collection;
            return $database . '.' . $collection;
        }
        return $collection;
    }
1035152
public static function toArrayRecursive($collection) {
		$arr = $collection;
		if (is_object($collection) && method_exists($collection, 'toArray')) {
			$arr = $collection->toArray();
		}

		return array_map(function ($v) {
			if (is_object($v) && method_exists($v, 'toArray')) {
				return static::toArrayRecursive($v);
			}
			return $v;
		}, $arr);
	}