/laraclaude:lc:slow-queries [analyze | fix | fix --dry-run | file-path | fix file-path]from laraclaude
Detects slow database queries via static analysis: missing indexes, queries in loops, and unbounded selects. Generates migration fixes.
Ships in laraclaude. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Detect potential slow queries through static analysis: missing indexes, queries inside loops, unbounded selects, and foreign key columns without indexes.
| Subcommand | Description |
|---|---|
| (no argument) | Scan the entire project for slow query patterns. Read-only report. |
fix | Generate migration(s) to add missing indexes. Asks for confirmation before each change. |
fix --dry-run | Show what index migrations would be generated without writing anything. |
[file-path] | Analyze a specific file for slow query patterns. Read-only. |
fix [file-path] | Fix slow query issues originating from a specific file, with confirmation. |
What to detect:
Columns used in where(), whereHas(), orderBy(), groupBy(), and having() clauses that lack a corresponding index in migrations.
How to scan:
Grep to find all query builder calls with column references:
->where('column_name', and ->where(['column_name' =>->whereHas('relation', (check the closure for column references)->orderBy('column_name')->groupBy('column_name')->having('column_name',$table->index('column_name') or $table->index(['column_name', ...])$table->unique('column_name') (unique indexes also serve as indexes)->primary(), ->unique(), or ->index()$table->foreignId('column_name') -- some databases auto-index FK columns, some don'tSeverity: Medium (depends on table size)
Fix: Generate a migration to add the missing index.
What to detect:
Database queries executed inside foreach, for, while, array_map, collect()->each(), or similar iteration constructs.
How to scan:
Grep to find loop constructs in PHP files.Read to load each file with loops and check for query builder or Eloquent calls inside the loop body:
Model::where(, Model::find(, Model::create(DB::table(, DB::select(->save(), ->update(), ->delete()->first(), ->get(), ->count()lc:find-n-plus-one)Severity: High (multiplied by loop iteration count)
Fix: Suggest refactoring to bulk operations:
Model::find($id) in loop -> Model::whereIn('id', $ids)->get()->keyBy('id')->save() in loop -> Model::upsert($records, ...)->create() in loop -> Model::insert($records)What to detect:
Queries using ->get() without ->limit(), ->take(), or ->paginate() on tables that could grow large.
How to scan:
Grep to find all ->get() calls (excluding ->get('key') which is Collection::get).->limit() or ->take() present -> safe->paginate() or ->simplePaginate() present -> safe->where() with a highly selective condition (e.g., where('id', $id)) -> safetimestamps() and many migration modifications are likely largeSeverity: Medium (could cause memory issues on large tables)
Fix: Suggest adding ->limit() or converting to ->paginate().
What to detect:
Foreign key columns defined in migrations without explicit indexes. While some databases (MySQL InnoDB) auto-create indexes for FK constraints, columns used as FKs via convention (ending in _id) but without actual FK constraints will not have indexes.
How to scan:
_id._id column has:
->foreign() constraint (MySQL auto-indexes these)->index() definition->foreignId() call (creates both column and index via constraint)_id columns that have neither a FK constraint nor an explicit index.Severity: Medium
Fix: Generate a migration to add indexes on unindexed FK columns.
What to detect: Queries that select all columns when only a few are needed, especially on wide tables.
How to scan:
Grep to find queries without ->select() on tables with many columns (15+).Model::all() usage.->get() without a preceding ->select().Severity: Low (performance impact varies by table width)
Fix: Suggest adding ->select() with only needed columns, especially in list/index views.
SLOW QUERY ANALYSIS
====================
CRITICAL (queries in loops)
----------------------------
1. Query inside foreach loop
File: app/Services/PropertyService.php:78
Loop: foreach ($propertyIds as $id)
Query: Property::find($id)
Impact: ~100 queries per request (estimated from context)
Fix: Refactor to Property::whereIn('id', $propertyIds)->get()
HIGH (missing indexes on frequently queried columns)
-----------------------------------------------------
1. Missing index on 'properties.status'
Queried in: 4 files
- app/Http/Controllers/PropertyController.php:32
- resources/views/livewire/properties/index.blade.php:15
- app/Services/SearchService.php:44
- app/Jobs/SyncPropertyJob.php:22
Table estimated size: Large (15+ migrations)
Fix: Add index migration
MEDIUM (unbounded selects)
---------------------------
1. Unbounded ->get() on 'activities' table
File: app/Http/Controllers/DashboardController.php:18
Query: Activity::where('organization_id', $id)->get()
Fix: Add ->paginate(50) or ->limit(100)
SUMMARY
========
Issues found: 12
Critical (queries in loops): 3
High (missing indexes): 5
Medium (unbounded selects): 3
Low (SELECT * patterns): 1
In fix mode, generate migrations for missing indexes:
Schema::table('properties', function (Blueprint $table) {
$table->index('status');
$table->index('organization_id');
});
For queries-in-loops and unbounded selects, show the suggested refactoring code but do not auto-apply (risk of breaking logic). Present as recommendations with file path and line number.
EXPLAIN on actual queries for definitive performance analysis.$table->foreignId() automatically get indexes in MySQL via the FK constraint. These are safe.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
32 skills in this plugin
/lc:analyze-errorPaste a Laravel stacktrace and get root cause analysis with suggested fix./lc:analyze-modelDeep analysis of a Laravel Eloquent model - relationships, scopes, casts, fillable, observers, keepers, actions./lc:api-docsGenerate API documentation from routes, controllers, and form requests./lc:blade-auditDetect hardcoded text without @text(), duplicate CSS classes, unused Blade components, and accessibility issues./lc:boost-inspectRuntime-verified Laravel inspection using the Laravel Boost MCP server (Tinker, Database Query/Schema, Last Error) instead of static grep. Falls back to Docker/Tinker if Boost is not installed./lc:cache-opportunitiesDetect repeated queries and computations that should be cached.npx claudepluginhub edulazaro/laraclaude --plugin laraclaudeOther plugins' skills for the same job