Skip to main content

Documentation Index

Fetch the complete documentation index at: https://kawax.biz/llms.txt

Use this file to discover all available pages before exploring further.

What this page covers

This page does not explain how to use collect(). It gives you a map for reading Laravel framework source code. This is for you if you already know Collection methods and now want to understand why the design looks the way it does.

Historical evolution

The Collection structure was significantly reorganized when LazyCollection was introduced.

Up to Laravel 5.8

  • Illuminate\Support\Collection
  • Illuminate\Database\Eloquent\Collection (extends Collection)
At this point, LazyCollection, Enumerable, and EnumeratesValues did not exist yet.

Changes in Laravel 6.0

With the introduction of LazyCollection, Laravel separated common APIs into Enumerable (interface) and EnumeratesValues (trait).

Current overall structure (Laravel 13)

Reference: laravel/framework v13.x
Current file paths are under src/Illuminate/Collections/*, but the namespace remains Illuminate\\Support. Check both path and namespace when reading source.

PHPDoc and PHPStan-style generics

PHP itself still has no native generics. Still, Collection-related classes express strong type information through PHPDoc. The main goals are:
  • Accurate IDE autocompletion
  • Better static analysis with PHPStan and Larastan

Common syntax

/**
 * @template TKey of array-key
 * @template-covariant TValue
 * @implements \Illuminate\Support\Enumerable<TKey, TValue>
 */
class Collection implements Enumerable
{
    /**
     * @use \Illuminate\Support\Traits\EnumeratesValues<TKey, TValue>
     */
    use EnumeratesValues;
}
SyntaxMeaning
@template TKey of array-keyRestricts key type to int|string
@template-covariant TValueTreats value type as covariant (safe narrowing to more specific types)
@implements ...<TKey, TValue>Passes type arguments to the implemented interface
@extends ...<TKey, TModel>Declares type arguments when extending a parent class
@use ...<TKey, TValue>Declares type arguments when applying a trait

How this looks in Eloquent Collection

/**
 * @template TKey of array-key
 * @template TModel of \Illuminate\Database\Eloquent\Model
 * @extends \Illuminate\Support\Collection<TKey, TModel>
 */
class Collection extends BaseCollection
{
}
Because TValue becomes concrete as TModel, type inference for methods like map() and filter() becomes model-aware.

1. Start with Enumerable

First, understand the contract. Knowing the method list here makes the rest much faster.

2. Follow common methods in EnumeratesValues

Most shared logic, including map, filter, and reduce, lives here. Then you only need to read the differences between Collection and LazyCollection.

3. Compare Collection and LazyCollection

  • Collection: stores arrays and evaluates eagerly
  • LazyCollection: uses Generator and evaluates lazily
Even for methods with the same name, evaluation timing and memory behavior differ.

4. Finish with Eloquent\Collection

Focus on model-specific extensions such as find, load, and modelKeys. It is easier to understand after you know base Collection.
When deep-diving one method, follow this order: declaration in Enumerable → implementation in EnumeratesValues → override checks in Collection / LazyCollection.
Last modified on April 23, 2026