webparking/laravel-type-safe-collection
Webparking's Laravel Type-Safe Collection adds strongly typed collections to Laravel. Define the permitted item class once to get runtime type checks, clearer errors, IDE autocompletion, and safer map/filter operations, keeping collection contents predictable and preventing mixed-type bugs.
OrderCollection, InvoiceCollection) as first-class domain objects that enforce invariants (a collection of invoices can only ever contain invoices), versus accepting Laravel's default mixed-type Collection and relying on runtime discovery of bad data.@extends Collection<int, User> generics docblocks, this package's value proposition is largely already met for free — which is itself a useful signal for deprioritizing the initiative.make() guard, a constructor type check, and @extends annotations. That is roughly 30–50 lines of in-house code. This package's build vs. buy calculation is unusually lopsided toward build, which makes it a good case study for a decision framework the team applies elsewhere.->map() and ->filter() pipelines from silently degrading into mixed; making IDE autocompletion reliable across collection chains; catching bad data at the boundary (e.g. hydrating from an API payload or a loosely-typed repository query) rather than three layers downstream.Consider if:
Look elsewhere if:
Recommended default: write the typed collection in-house and skip the dependency. Revisit adoption only if an audit shows this package is already transitive in the tree.
To executives: This is a low-cost, low-risk, low-strategic-value item — not a budget decision. It is a small community library that enforces type constraints on data collections. The honest framing is that the pattern is worth adopting and the package is not: the last release was 2020, it has 37 stars, and the same capability is a half-day of internal engineering with no ongoing vendor exposure. Recommendation: adopt the pattern in-house, avoid the dependency, and record the decision so it doesn't resurface.
To engineering: This package forces a single type on a Laravel Collection, catching type drift in map/filter/pluck chains at runtime and improving IDE inference. It works, and the source is a clean reference. But it has been unmaintained since September 2020, predates Laravel 9–12, and has essentially no adoption community behind it. If your analyzer already reads @extends Collection<int, Model> docblocks, this adds runtime enforcement you likely don't need. Proposed: implement a typed base collection internally following the same shape (make() guard + constructor check + generic annotation), and put the saved dependency budget toward wiring PHPStan into CI, which delivers broader and more durable value.
How can I help you explore Laravel packages today?