Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Laravel Eloquent N+1 Query Detector and Fixer

    by Saizul Amin

    1

    Detect and fix Laravel Eloquent N+1 query patterns using Telescope exports or query logs.

    $7

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Laravel Eloquent N+1 Query Detector and Fixer

    Laravel Eloquent N+1 Query Detector and Fixer

    Example session with this skill installed

    Run the Laravel Eloquent N+1 Query Detector and Fixer skill on my project and give me a prioritised list of what to fix, with exact changes.

    • Read your context and instructions
    • Compiled the laravel eloquent n+1

    Here is what the Laravel Eloquent N+1 Query Detector and Fixer skill produced.

    Demo: real, unedited output of the skill's bundled script on a sample input from its test suite.

    Output

    21 queries in 1 request(s); 1 N+1 pattern(s)
    
    #1 x10 in one request (1 request(s), 10 queries, 0.0 ms)
       select * from prices where prices.product_id = ?
       fix: hasMany/hasOne: each product loads its prices. Eager load it: ->with('prices').
    

    What you do next

    1. Fix the highest-severity items first.
    2. Ask your agent to apply the fixes it suggests, then run the skill again to confirm.
    3. Keep the skill installed and re-run it whenever the project changes.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Database bottlenecks in Laravel often stem from N+1 query patterns that go unnoticed until a page feels sluggish. This skill identifies those redundant queries from logs or Telescope exports and provides the exact eager-loading syntax to fix them.

    What it does

    • Pattern detection analyzes query logs or JSON exports to find repeated SELECT statements executed in loops.
    • Root cause mapping identifies the specific file and line number triggering the queries using Telescope metadata or log traces.
    • Fix generation recommends the correct Eloquent method such as with(), load(), withCount(), or withSum().
    • Lazy loading audits detects and reports violations triggered by Model::preventLazyLoading().
    • Regression testing helps verify that query counts dropped after applying fixes by comparing request captures.

    How it works

    1. Capture logs by exporting Telescope query entries, enabling DB::listen in a service provider, or using DB::getQueryLog().
    2. Execute detection by running the script against your log file or JSON export to group queries by request ID.
    3. Analyze results to see a breakdown of repeated patterns, execution counts, and the suggested eager-loading fix.
    4. Apply and verify by updating the controller or model and re-capturing queries to confirm the optimization.

    Frameworks & tools

    This skill is built for Laravel 8+ applications. It utilizes Python 3.8+ for log parsing and integrates with Laravel Telescope or standard PHP logs.

    Why this beats prompting it yourself

    Generic LLMs often struggle to count occurrences accurately across thousands of log lines or miss subtle differences in SQL bindings. This skill uses a deterministic script to group queries by request ID, ensuring you never miss a loop-based query even in massive log files.

    Use cases

    • Optimize slow API endpoints returning hundreds of duplicate database queries.
    • Debug Blade views where relation access inside a @foreach loop causes lag.
    • Implement strict lazy-loading guards to prevent future performance regressions.
    • Audit Livewire components that trigger database calls on every property update.

    Known limitations

    Does not optimize single slow queries caused by missing indexes. Requires query logging or Telescope to be active during the request capture phase.


    Open source: saizul/laravel-php-skills on GitHub (MIT licence, by Saizul Amin).

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.

    Requires Laravel 8+ for full feature set. Optimized for request-based logs; does not diagnose slow queries caused by missing DB indexes or non-database bottlenecks.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Frequently Asked Questions

    This skill identifies N+1 query patterns where Eloquent models are loaded individually in loops. It analyzes your logs to find repeated SELECT statements and provides the exact 'with()' or 'load()' syntax needed to fix the bottleneck.

    The skill is optimized for Laravel 8 and above. It works by processing exports from Laravel Telescope or standard query logs generated via DB::listen or DB::getQueryLog.

    You will receive the AI agent skill configuration, the deterministic parsing logic for high-volume log analysis, and a guide on how to export your query data for the most accurate results.

    Unlike generic prompts that can hallucinate query counts, this skill uses a deterministic script to group thousands of log lines by Request ID. This ensures 100% accuracy in detecting loops that are often too large for a standard LLM context window.

    No, this skill focuses on identifying redundant queries caused by missing eager loading. It does not analyze query execution plans or suggest missing database indexes for individual slow queries.

    Yes, you can use the skill to compare query logs from before and after your changes. This 'Regression Testing' workflow confirms that the total number of database hits has successfully decreased.

    New in Data & Databases