Why N+1 Queries Hurt Laravel Performance
N+1 queries are one of the most common reasons Laravel dashboards slow down under real traffic. A single page can jump from 12 SQL statements to 400+ when relationships are loaded inside loops.
Step 1: Measure Before You Refactor
Start with Laravel Telescope or Clockwork on staging. Filter requests above 200ms and inspect the query tab. If you see the same table queried dozens of times with different IDs, you have an N+1 pattern.
Step 2: Replace Loops with Eager Loading
- Use
with()for standard relationships - Use
withCount()when you only need counts - Use
load()after conditional logic when eager loading upfront is wasteful
Step 3: Validate in Production Safely
After refactoring, compare P95 response time and total queries per route. Most LaravelOps clients see 60–90% fewer queries on reporting pages within one sprint.
Need a full performance audit? Book a Laravel performance review with our team.