doctrine/collections
Doctrine Collections is a PHP library providing powerful collection abstractions, including ArrayCollection, typed collections, Criteria filtering, expression-based matching, selectors, and iterators for flexible data manipulation.
Architecture fit. doctrine/collections is a framework-agnostic, pure-PHP abstraction library (interfaces: Collection, ReadableCollection, Selectable; implementations: ArrayCollection, AbstractLazyCollection; utilities: Criteria, ExpressionBuilder). It sits cleanly beside Laravel rather than inside it: no service providers, no configuration, no container bindings, no global helpers. That makes it a low-coupling dependency that can be introduced into domain or persistence layers of a Laravel codebase without touching the framework's bootstrapping. Its natural home is code that already models Doctrine-style persistence concerns (criteria-based filtering, lazy hydration, ordered sets) — not view-layer or controller logic where Illuminate\Support\Collection is the idiomatic fit.
Integration feasibility. Composer-only onboarding: composer require doctrine/collections:^2.6 (or ^1.8 for legacy PHP baselines). PSR-4 autoloading, no artisan commands, no published assets, no migrations. Install-to-first-use is effectively minutes. The real constraint is PHP baseline compatibility (see risk below), not framework integration effort. For teams already running laravel-doctrine/orm or doctrine/orm transitively, the library is already present and the "integration" is a policy decision about whether to depend on it directly.
Technical risk. Three concerns are material:
final, added readonly, introduced Selectable into ReadableCollection, and deprecated Order. Any code that subclasses ArrayCollection or type-hints against pre-3.0 interfaces will break on major upgrades. This is a planned-upgrade dependency, not a free-upgrade one.Key questions.
doctrine/collections already present transitively via doctrine/orm, laravel-doctrine, or another dependency? If so, direct adoption is a governance decision, not a new vendor.Criteria/ExpressionBuilder/lazy collections, or is Illuminate\Support\Collection sufficient? If the latter, opportunity value is near zero.Stack fit. Composer-native and PSR-4, so it drops into Laravel 9–12 without ceremony. It is explicitly not a replacement for Illuminate\Support\Collection — those two should be scoped to different layers. Recommended placement: service/domain layer and any Doctrine-adjacent persistence code; keep it out of controllers, Blade, and HTTP resources. If the estate does not use Doctrine ORM anywhere, treat this as an optional utility, not a required dependency.
Migration path. Two viable entry points:
^2.6 in new domain packages where criteria-based filtering or lazy collections genuinely simplify code. No migration cost.Avoid a wholesale retrofit of existing Illuminate\Support\Collection usage; the two APIs overlap enough that partial conversion creates inconsistency without clear benefit.
Compatibility. Pin to ^2.6 (PHP 8.1–8.3 friendly) for the current Laravel fleet. Reserve ^3.1 for when the platform minimum is PHP 8.4. Do not allow any constraints — the 1.x/2.x/3.x differences are real (return types, final classes, readonly, removed deprecations). Note that 3.1 deprecates the Order enum, so even within a major line, deprecation tracking is warranted. Static-analysis story is strong (Psalm/PHPStan annotations are actively maintained), which reduces integration friction in typed codebases.
Sequencing.
composer why doctrine/collections across the fleet; establish transitive presence and resolved versions.^2.6 as the standard.Maintenance. Maintained under the Doctrine organization with a long, steady release cadence (1.x through 3.1 visible in the provided release history), MIT-licensed, and backed by well-established community stewardship. Patch releases are small and focused (named-argument deprecations, PHPDoc corrections, static-analysis fixes), which signals a disciplined, low-churn maintenance posture — good for a library that sits deep in a dependency graph.
Support. No commercial SLA. Support is community- and documentation-driven; the README is deliberately minimal (as the excerpt shows), so institutional knowledge must be built internally. Risk is concentrated in the major-version upgrade decision, not in day-to-day operation.
Scaling. Runtime cost is negligible — ArrayCollection wraps native arrays; AbstractLazyCollection is designed specifically to defer work on large result sets, which is a scaling advantage for paginated or criteria-filtered data. Memory profile is array-equivalent. No I/O, no external services, no network calls, so there is no scaling cliff to model.
Failure modes.
final classes in 3.x will break extension patterns; audit for subclasses of ArrayCollection before any major upgrade.ExpressionBuilder/Criteria used to construct queries from user input is a security-relevant pattern; it belongs behind validation and allow-listing, not in request-handling code.Ramp-up. Low for the core API (add, filter, map, findFirst, reduce, matching). The learning curve is in judgment, not syntax: engineers must know when a Doctrine collection is appropriate versus when Illuminate\Support\Collection is the right tool. Budget half a day of onboarding plus the one-page convention doc from the sequencing step; that is the realistic adoption cost.
How can I help you explore Laravel packages today?