audunru/eager-load-pivot-relations
Strengths:
BelongsToMany relationships with pivot relations/attributes, a common pain point in Laravel applications (e.g., procurement, inventory, or multi-table systems).items.pivot.unit.someRelation) in a single query.as('planItem')) allow for cleaner API design and avoid magic strings like pivot.Limitations:
BelongsToMany relationships; unrelated queries (e.g., HasOne, HasMany) remain unaffected.PlanItem) for advanced use cases, adding slight complexity to model setup.DB::select()).EagerLoadPivotTrait) minimizes invasive changes. Only models using BelongsToMany with pivot relations need modification.composer require + trait usage, reducing deployment friction.ajcastro) with 9 stars and active maintenance (last release: 2026-05-25).pivot.unit.someBelongsToManyRelation) may require deeper query inspection in logs or tools like Laravel Debugbar.BelongsToMany relationships with pivot relations/attributes (e.g., plan_item.unit_id), or are simpler pivots sufficient?join()? (Trade-off: less maintainable.)BelongsToMany relationships and pivot relations/attributes.user_id + role_id).BelongsToMany relationships with pivot attributes/relations (e.g., plan_item with unit_id).DB::enableQueryLog()).composer require audunru/eager-load-pivot-relations).EagerLoadPivotTrait to the parent model (e.g., Plan).BelongsToMany definition to include:
->using('PivotModel') (if custom pivot exists).->withPivot('attributes').->as('customAccessor') for cleaner syntax.with('relation.pivot.relation').when($showUnits, 'items.pivot.unit')) to avoid over-fetching.Plan::with('items.pivot.unit')->get() for procurement plans.BelongsToMany queries that currently use load() or manual joins.with('relation.pivot.relation')).EagerLoadPivotTrait to parent models.spatie/eloquent-sortable) may be needed.How can I help you explore Laravel packages today?