ajcastro/eager-load-pivot-relations
Laravel package that eager loads relations defined on pivot models in many-to-many relationships, eliminating N+1 queries when accessing nested pivot data. Use familiar Eloquent syntax to keep role_user, post_tag, and similar pivot records fast and clean. Drop-in trait and builder methods make setup...
Pivot models can declare relations but cannot eager load them. This package closes that gap, so a product team can keep a normalized join-table model instead of denormalizing or hand-rolling with() joins.Pivot classes that declare belongsTo/hasMany relations, you are hitting N+1 queries on collection endpoints, and you want to avoid restructuring the schema or replacing Eloquent relationships with manual query builders.JOINs or post-query hydration) would leak persistence concerns into controllers or resources.->with() on the parent query plus a post-hydration pass is sufficient. Also look elsewhere if you need eager loading on polymorphic pivot relations or through-tables beyond what this package documents.Executives — one line: A small, free, open-source Laravel add-on that removes a class of database performance problems in our list and reporting screens, at the cost of one dependency and a modest, reversible integration effort.
Engineering — the substance: Laravel lets a custom pivot model declare relationships but does not eager load them, which forces either N+1 queries or manual join/hydration code on every collection that renders join-table data. This package adds the missing eager-loading behavior so we can keep a normalized schema and idiomatic Eloquent. The trade-off is maturity: it is a 0.x release from a single-maintainer project, and the v0.3.0 notes are a PR link rather than a curated changelog. Recommendation is to adopt behind our own thin wrapper — an interface or scope that owns the with() call sites — so we get the query-count win now and can swap the implementation out without touching domain code. Budget roughly a day for the spike, a day for the wrapper plus tests, and a query-count assertion in CI to prove the gain and catch regressions on future upgrades.
How can I help you explore Laravel packages today?