- Home
- Skills
- Data & Databases
- Laravel Eloquent N+1 Query Detector and Fixer
Works with the AI Agents you already use
Laravel Eloquent N+1 Query Detector and Fixer
by Saizul Amin
Detect and fix Laravel Eloquent N+1 query patterns using Telescope exports or query logs.
$7
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
- Fix the highest-severity items first.
- Ask your agent to apply the fixes it suggests, then run the skill again to confirm.
- 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
SELECTstatements 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(), orwithSum(). - 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
- Capture logs by exporting Telescope query entries, enabling
DB::listenin a service provider, or usingDB::getQueryLog(). - Execute detection by running the script against your log file or JSON export to group queries by request ID.
- Analyze results to see a breakdown of repeated patterns, execution counts, and the suggested eager-loading fix.
- 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
@foreachloop 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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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.
Trust & safety
Security scan
Security scan passed 1 day ago
- Software
Python 3.8+