Laravel Eloquent Performance
summary
Demo app has 250 wants, 6,500 comments and 30,000 votes and uses Laravel tools like Debugbar with a models collector. Techniques shown: replace loading 250 models for a dashboard with one query using conditional aggregates, build a dynamic relationship that returns last_comment_id via a select subquery and eager load it, and avoid N+1 by calling setRelation to attach already-loaded models. Examples reduce queries from dozens (83, 161) down to about five or six and cut hydrated models and memory.
AI-written summary · about
