Mohamed Hassan

Mohamed Hassan

This author hasn't written a bio yet.

1 article published

Why is my Laravel page running hundreds of queries? (The N+1 problem, explained) You're loading a list of models, then touching a relationship on each one inside a loop. Laravel runs 1 query for the list + 1 query per row for the relationship. That's the N+1 problem. The fix is to tell Eloquent up front which relationships you need, with with(), so it loads them in one extra query instead of N. Nov 20, 2026 · 4 min read