Skip to content
PromptPilot AI

Library / Coding & Technology / Performance

Laravel: find and fix N+1 queries

Eager loading fixes with proof.

Cursor / coding agentsClaude CodeChatGPTClaudelaravel
Who it's for
Developers using AI coding tools
Use case
Performance
Output
Agent task · Free
You'll need to fill in
controller / page / API resource
Prevents: Adds with() everywhere blindly, or misses the real N+1 in a Blade/Resource loop.
Find N+1 query problems in [controller / page / API resource].

1. Trace which relationships are accessed inside loops (controllers, Blade views, API Resources, Livewire components).
2. Fix with eager loading (with(), load(), withCount()) only where needed.
3. If useful, suggest enabling Model::preventLazyLoading() in non-production environments.
4. Show the before/after query count from a feature test using DB::enableQueryLog() or similar.
Don't change response shape or behaviour.

Copies your prompt and opens the official site in a new tab. You may need to paste it yourself (Ctrl/⌘ + V). Nothing is sent to the AI by us.

Replace [bracketed] parts with your own details before sending. Want it tailored? Build a custom website & app development prompt.

Before vs after

A typical one-line request compared with this prompt. We only show sample responses where we've written an illustration.

BeforeWhat people usually type

Prompt

performance

1 words · no role, context, format or constraints

AfterThis library prompt

Prompt

Find N+1 query problems in [controller / page / API resource].

1. Trace which relationships are accessed inside loops (controllers, Blade views, API Resources, Livewire components).
2. Fix with eager loading (with(), load(), withCount()) only where needed.
3. If useful, suggest enabling Model::preventLazyLoading() in non-production environments.
4. Show the before/after query count from a feature test using DB::enableQueryLog() or similar.
Don't change response shape or behaviour.

66 words · generated instantly from templates, no AI called

What we added

  • Your details: [brackets] for the facts only you know
  • Step-by-step workflow: numbered steps

Related prompts