nunomaduro/laravel-any
Nuno Maduro's tiny Laravel helper that resolves any class through the service container, automatically injecting its dependencies so you can instantiate objects with zero boilerplate.
Dependency-governance policy — a low-stakes precedent for a real gate. This package is the ideal worked example for setting a minimum adoption bar: 38 stars, 0 dependents, a 0.25 composite score, MIT licence. It lets you socialise objective criteria — adoption signals, maintenance cadence, security-contact availability, licence fit, and overlap with native framework capability — without picking a fight over something the business actually depends on. Use it to justify a written "no unmaintained micro-packages in production" standard. The principle lands better when the example is trivially replaceable.
Build-vs-buy calibration — the cleanest test case available. The entire shipped capability is a single Collection::any(callable): bool macro that short-circuits on the first matching item: roughly six lines of first-party code. It is the reference point for "when is a dependency cheaper than writing it ourselves?" — and the answer here is never. Every later dependency request can be measured against this baseline: does it do more than six lines of work? Does it carry maintenance we would otherwise own? Does it have a future beyond the next framework upgrade?
Framework-upgrade and language-roadmap risk — PM-owned, not just engineering's. The capability is being absorbed upstream: Laravel 9+ ships native Collection::any() and PHP 8.4 adds array_any(). Adopting today creates a guaranteed cleanup ticket at the exact moment of a framework or language upgrade — dead weight against the twelve-month platform roadmap. PMs own upgrade cadence and the resulting maintenance budget, so this risk sits with us, not only with the engineers who type composer require.
Developer-experience and coding-standards ownership. If the team genuinely values JS-style any/some ergonomics in guard clauses, the decision is a one-line entry in an internal CollectionMacrosServiceProvider plus a note in the style guide — not a roadmap item. The PM owns whether the ->any() idiom is standardised across the codebase; engineering owns how it is implemented. Splitting the decision that way stops a style preference from quietly becoming an architectural dependency.
Roadmap positioning — explicitly out of scope, and useful as such. Low effort, low differentiation, zero customer-facing impact. This belongs in internal tooling, test assertions, admin utilities, and engineering onboarding. Never on a customer-facing roadmap. It is a genuinely useful teaching artefact for onboarding PMs on how little qualifies as roadmap-worthy, and on how to separate an ergonomics preference from a product decision.
Use cases to cite when the topic surfaces — each already has a first-party equivalent:
$invoices->any(fn ($i) => $i->isExpired()) before throwing a domain exception.$users->filter(fn ($u) => $u->isActive())->any(fn ($u) => $u->hasFlag('suspended')).Eloquent\Collection extends the base collection.assertTrue($items->any(...), 'message') gives clearer failure output than contains().The one use case that is not supported, and where PMs get burned on performance: this is in-memory only. $tenant->subscriptions()->any(...) runs SELECT * and then iterates in PHP. When the underlying question is existence, the answer is ->where(...)->exists() in SQL, not a collection macro.
A concrete pre-adoption check to put in the ticket:
php artisan tinker --execute="var_dump(method_exists(Illuminate\Support\Collection::class, 'any'));"
composer show laravel/framework | grep versions
If that prints true, the behaviour already exists with identical semantics — stop.
Consider adoption only when all of the following hold:
any() (broadly pre-Laravel 9), so the macro is not shadowing or duplicating core behaviour. Verify first with method_exists(Illuminate\Support\Collection::class, 'any').->any() idiom and prefers a published package over an internal macro for consistency or discoverability. Defensible, but weak — the ergonomics are identical either way.Look elsewhere — or build in-house — when:
Collection::any() exists natively with identical semantics; installing the package creates two competing implementations and a silent registration-order bug on upgrade.array_any() makes the dependency redundant, so adopting now guarantees a removal ticket later.contains($callback) already delivers the same readability and identical semantics — including short-circuiting — with zero new dependencies. This is the correct default answer for most teams.Known gotchas to hand to engineering with the decision, not after it: confirm whether the macro compares with === or == before first merge and lock it with a test (loose comparison is the one real defect class — silent boolean drift no review catches); make sure the provider is registered and config:cache is rebuilt, or queue workers and early-booting Artisan commands throw BadMethodCallException; register unconditionally so Octane and long-running workers cannot boot without the macro; remember any() on an empty collection returns false, which is not the negation of every(); and if you do ship it, note it in the ADR, run composer audit in CI, and file the removal ticket the day you install it.
For executives — one line: this is a six-line convenience macro that duplicates capability Laravel now ships natively, so our recommendation is to standardise the idiom internally and not take the dependency; the decision costs nothing today and saves a cleanup ticket at the next platform upgrade.
For engineering — the substance: on Laravel 9+ this is pure overhead — Collection::any() already exists with identical short-circuiting semantics, and installing the package gives two competing implementations resolved by provider registration order. On older versions the same behaviour is six lines in one CollectionMacrosServiceProvider, which we control, test, and can retire in a single commit. We keep the ergonomics we like ($invoices->any(fn ($i) => $i->isExpired()) in guard clauses, pipelines, Eloquent collections, policies, and test assertions), and we keep the manifest clean. We also get to choose our own comparison semantics explicitly rather than inheriting whatever == versus === the package happens to use.
Framing that travels well: this package is our worked example for dependency hygiene — low adoption signals (38 stars, 0 dependents), a single capability overlapping native framework and language features, and zero extension points. Treating it as the floor of the adoption bar sets a defensible precedent that costs the business nothing to enforce, and gives every future "can we just add this package?" conversation a shared reference point. It is an internal tooling and onboarding decision, not a product decision, and it should never appear on a customer-facing roadmap.
How can I help you explore Laravel packages today?