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 usecollect().
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 whenLazyCollection was introduced.
Up to Laravel 5.8
Illuminate\Support\CollectionIlluminate\Database\Eloquent\Collection(extendsCollection)
LazyCollection, Enumerable, and EnumeratesValues did not exist yet.
Changes in Laravel 6.0
With the introduction ofLazyCollection, 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
| Syntax | Meaning |
|---|---|
@template TKey of array-key | Restricts key type to int|string |
@template-covariant TValue | Treats 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
TValue becomes concrete as TModel, type inference for methods like map() and filter() becomes model-aware.
Recommended reading order
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 eagerlyLazyCollection: usesGeneratorand evaluates lazily
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.