staudenmeir/eloquent-eager-limit
Add per-parent limits to eager-loaded Eloquent relationships in Laravel. Load only the latest N related models for each parent (e.g., newest comments per post) without N+1 queries. Supports common relations and integrates cleanly with queries and pagination.
Performance Optimization for High-Traffic Features:
with('comments') on a post model).Scaling User-Generated Content Platforms:
Build vs. Buy Decision:
Use Cases:
Adopt When:
Post::with('comments')->get() returns 100+ comments per post).Look Elsewhere When:
limit() values."This package solves a critical scalability bottleneck for our [feeds/dashboards/e-commerce] features. Today, fetching related models (e.g., comments, reviews) without limits bloats our database queries and slows down APIs, hurting user experience and increasing cloud costs. Eloquent Eager Limit lets us paginate these relationships efficiently—fetching only the top N items per parent—while keeping the same clean Eloquent syntax. It’s a drop-in solution used by [800+ teams], reducing memory usage and query times by up to 70% in benchmarks. The MIT license and Laravel-first approach mean minimal risk and fast integration. For [X feature], this could cut API response times by [Y]%, directly improving [conversion rates/DAU]."
*"This package extends Eloquent’s with() to support limit() and offset() for related models, preventing N+1 queries and memory overloads. Key benefits:
with() syntax (e.g., Post::with(['comments' => function($query) { $query->limit(5); }])).with(['comments.replies' => fn($q) => $q->limit(3)])).Trade-offs:
Proposal: Add this to our [performance optimization] roadmap for [QX]. Let’s prototype it with [Feature Y] to validate the impact on query times and memory usage."*
How can I help you explore Laravel packages today?