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.

Mohamed Hassan Mohamed Hassan Nov 20, 2026 · 4 min read
Read the article

Most read

  1. 01 Why is my Laravel page running hundreds of queries? (The N+1 problem, explained) 40 reads