$ recombobulate _
home / tips / let-claude-fix-your-eloquent-n1-query-problems
0

Let Claude Fix Your Eloquent N+1 Query Problems

bagwaa @bagwaa · Mar 25, 2026 · Debugging
let-claude-fix-your-eloquent-n1-query-problems

N+1 queries are one of the most common Laravel performance killers and they're easy to miss — your code looks fine but you're firing hundreds of database queries on every request.

Paste your controller or service method and ask Claude to spot and fix them:

@UserController.php @PostController.php

Find any N+1 query problems in these files and fix them 
with eager loading. Explain what each one was doing.

Claude will rewrite your queries with the right with() or load() calls and explain exactly why each change matters:

// Before — fires one query per user to get their posts
$users = User::all();
foreach ($users as $user) {
    echo $user->posts->count();
}

// After — two queries total, regardless of user count
$users = User::with('posts')->get();
foreach ($users as $user) {
    echo $user->posts->count();
}

You can also ask Claude to go further and add nested eager loading for deeper relationships, or switch to withCount() when you only need totals:

Now check for nested N+1s in the relationships too, 
and use withCount() where we only need the count.

If you have Laravel Debugbar or Telescope installed, paste the query log output alongside your code — Claude can match up the duplicate queries to the exact lines causing them.

N+1 problems compound fast at scale — catch them in review, not in production.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Detect and Fix Memory Leaks in Your Node.js Application with Claude

Hand Claude your heap snapshots or server code and ask it to trace memory leaks — it spots missing event listener cleanup, unbounded caches, and stream lifecycle bugs that are easy to miss in code review.

bagwaa @bagwaa · 2 hours ago
0
Audit Your UI Components for Accessibility Issues with Claude

Ask Claude to audit your UI components for WCAG accessibility issues — it catches semantic problems, missing ARIA attributes, and keyboard navigation gaps that automated tools miss.

bagwaa @bagwaa · 2 hours ago
0
Debug API and MCP Issues with --debug

The --debug flag enables verbose logging for Claude Code, and an optional category filter like "api,mcp" lets you narrow output to exactly the subsystem you need to investigate.

bagwaa @bagwaa · 5 hours ago