inani/lazy-belongs-to-many
Laravel package that adds a lazy-loading belongsToMany relationship, letting you defer large many-to-many queries until the collection is actually accessed. Keeps models light while still supporting pivot data, eager loading, and standard relationship methods.
Architecture fit
belongsToMany," meaning it reimplements or extends a core framework contract (Illuminate\Database\Eloquent\Relations\BelongsToMany / Relation) rather than sitting alongside it.with), constraint merging, wherePivot, withPivot, sync/attach/detach, touch, chaperone, serialization, and withCount.Integration feasibility
composer require inani/lazy-belongs-to-many, add a trait or return the custom relation from a model method. No service provider complexity, no infrastructure, no schema migration implied.Technical risk — High
BelongsToMany surface. Gaps surface as silent wrong results (missing pivot columns), broken eager loading (reintroducing N+1 at scale), or incorrect counts — the hardest class of bug to detect in review.with eager loading, chaperone(), withCount, wherePivot, chunking, composite indexes, or a read-model/caching layer).Key questions
belongsToMany + eager loading + indexing does not? Request the maintainer's benchmark or reproduce it internally.Relation subclass, a trait, or a query-builder wrapper? This determines the blast radius.BelongsToMany API — sync, attach, wherePivot, withPivot, withTimestamps, touch, chaperone, withCount, and JSON serialization?Stack fit
Migration path
belongsToMany.chaperone(), withCount, pivot indexes, selective column loading, chunking, caching. Document the residual gap.BelongsToMany method the app actually uses.Compatibility
Sequencing
Maintenance
Support
Scaling
Failure modes
Ramp-up
TPM verdict: Score 0.18 and zero dependents are disqualifying for broad adoption. Pursue only as a scoped, time-boxed experiment with a mandatory benchmark gate, an explicit native-alternatives comparison, and a pre-committed fork plan. Default recommendation: do not adopt; solve the underlying problem with native Eloquent and indexing.
How can I help you explore Laravel packages today?