• CRITICAL
  • REFACTOR
  • REVIEW
  • CLEAN

How to detect Laravel N plus one queries with your AI

Connect your AI to your codebase to catch expensive database loops. Your agent scans your Eloquent models to find where lazy-loading is killing your performance.

Ask AI about this page

Short answer

How do I find N plus one queries in Laravel?

Your AI scans your Eloquent models and controllers to find where lazy-loading triggers excessive database hits. It identifies the exact lines where you need to use eager loading. You'll get a list of problematic relationships and the code to fix them.

Where your fixes land.

The outcomes of your scan.

The AI categorizes every discovery into actionable buckets.

CRITICAL

Immediate bottlenecks

The AI finds high-impact loops that will slow down your app under load. You get the specific model and relationship causing the lag.

REFACTOR

Code improvements

These are subtle lazy-loading issues that drag down response times. Your agent provides the specific with() calls to add to your queries.

REVIEW

Human verification

The AI flags complex or nested relationships it can't confidently refactor. You decide if the suggested eager loading is safe for your data.

CLEAN

Optimized code

Once you apply the fixes, the AI confirms the relationship is now eager-loaded. This ensures your database hits stay constant.

The workflow

What your AI does when the code arrives.

The AI acts as a specialized static analysis tool for your Eloquent logic.

  1. Scan relationships

    The AI reads your Eloquent models to map out how data is connected. It looks for patterns where a loop calls a relationship property.

    validate_laravel_excellence
  2. Identify loops

    It traces controller logic to see if you're iterating over collections while accessing un-loaded relations.

    validate_laravel_excellence
  3. Suggest eager loading

    The agent writes the specific eager loading syntax needed to fix the detected issue.

    validate_laravel_excellence
  4. Verify fixes

    The AI re-checks the updated code to ensure the N plus one pattern is gone.

    validate_laravel_excellence

Try it

Copy these to start.

Use these prompts to kick off the analysis.

Starting points

Replace the bracketed text with your actual file paths or model names.

Laravel Excellence Prover Connector

You're all set. Choose your MCP client and follow the setup instructions.

Connector linkhttps://edge.vinkius.com/vk_preview_xVT6WxKnn5P5RXCAVRvEGptio7bgnTnovi5pfdfY/mcp

Claude Desktop

Follow the steps below to connect in seconds.

  1. 1In Claude Desktop, open Settings → Connectors.
  2. 2Click “Add custom connector” and paste the connector link above as the remote MCP server URL.
  3. 3Click Add and start a new chat — Laravel Excellence Prover capabilities are ready to use.
Configuration · claude_desktop_config.jsonCopy
{
  "mcpServers": {
    "laravel-excellence-prover-mcp": {
      "url": "https://edge.vinkius.com/vk_preview_xVT6WxKnn5P5RXCAVRvEGptio7bgnTnovi5pfdfY/mcp"
    }
  }
}
Copy into chat04
  • Scan my User model and its relationships for N plus one issues.

  • Check the Controller in app/Http/Controllers/OrderController.php for lazy-loading bottlenecks.

  • Review this loop in my recent pull request and suggest eager loading fixes.

  • Find all places in the Product repository where I'm missing eager loading on the Category relationship.

  • Claude
  • ChatGPT
  • Cursor
  • VS Code
  • Windsurf
  • Claude Code
  • JetBrains
  • Cline

Start here

Connect Laravel Excellence Prover once, then ask.

Just link the MCP to your client. Your credentials stay encrypted, and you can start querying your code immediately.

Connect Laravel Excellence Prover to your AI

FAQ

How this task behaves.

  • 01

    Can the AI automatically rewrite my files?

    No. The AI identifies the issues and suggests the code, but you must manually apply the changes to your files.

  • 02

    Does it scan my entire database?

    No. It only analyzes your Eloquent models and the code that interacts with them.

  • 03

    Will it find issues in raw SQL queries?

    No. This tool is specifically designed to find N plus one issues caused by Eloquent lazy-loading.

  • 04

    Can it fix performance issues in my migrations?

    No. It focuses on application-level logic and relationship loading, not database schema optimization.

  • 05

    How does it know which relationships are loaded?

    It analyzes the code execution paths and model definitions to determine if a relationship is being called on a collection without being eager-loaded.

  • More questions about Laravel Excellence Prover? The Connector page answers them. See everything the Laravel Excellence Prover Connector can do

Connect Laravel Excellence Prover to Claude, Cursor, ChatGPT & more