Optimizes Laravel database performance: Eloquent queries, indexing, Redis caching, N+1 prevention, and migration patterns.
Ships in asyrafhussin-agent-skills-1. 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.
Read when SKILL.md points to them.
Comprehensive database optimization guide for Laravel 13 applications. Contains 33 rules across 9 categories for writing performant database queries, proper indexing, efficient caching, naming conventions, and debugging slow queries in Laravel 13.
Reference these guidelines when:
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Query Performance & N+1 | CRITICAL | query- |
| 2 | Indexing Strategies | CRITICAL | index- |
| 3 | Eloquent Optimization | HIGH | eloquent- |
| 4 | Caching with Redis | HIGH | cache- |
| 5 | Pagination & Large Datasets | HIGH | data- |
| 6 | Transactions & Locking | HIGH | lock- |
| 7 | Migrations | HIGH | migrate- |
| 8 | Query Debugging | MEDIUM | debug- |
| 9 | Naming & Structure | HIGH | naming- |
query-eager-loading - Use eager loading to eliminate N+1 queriesquery-prevent-lazy-loading - Prevent lazy loading in developmentquery-auto-eager-loading - Configure automatic eager loading on modelsquery-select-columns - Select only needed columns instead of SELECT *index-foreign-keys - Index all foreign key columnsindex-composite-indexes - Create composite indexes for multi-column queriesindex-covering-indexes - Use covering indexes for read-heavy queriesindex-full-text - Use full-text indexes for search functionalityeloquent-query-builder-hot-paths - Use query builder for performance-critical pathseloquent-with-count-aggregates - Use withCount instead of loading relations to counteloquent-subquery-selects - Use subquery selects to avoid extra querieseloquent-where-has-optimization - Optimize whereHas with whereIn subqueriescache-remember - Use Cache::remember for expensive queriescache-invalidation - Invalidate cache on model changescache-tags - Use cache tags for group invalidationcache-ttl - Set appropriate TTL values for cached datadata-cursor-pagination - Use cursor pagination for large datasetsdata-chunk-by-id - Process large datasets with chunkByIddata-cursor-iteration - Use lazy cursors for memory-efficient iterationdata-avoid-unbounded - Never use unbounded queries on large tableslock-short-transactions - Keep transactions short and focusedlock-deadlock-retry - Implement deadlock retry logiclock-pessimistic-locking - Use pessimistic locking for critical updatesmigrate-zero-downtime - Write zero-downtime migrationsmigrate-concurrent-indexes - Create indexes concurrently in productionmigrate-safe-column-additions - Add columns safely without locking tablesdebug-explain-analyze - Use EXPLAIN ANALYZE to understand query plansdebug-laravel-debugbar - Use Laravel Debugbar to find query bottlenecksdebug-slow-query-log - Enable and monitor slow query logsnaming-tables - Table naming conventions (plural snake_case, pivot alphabetical)naming-columns - Column naming conventions (FKs, booleans, timestamps, polymorphic)naming-relationships - Relationship method naming (singular/plural matching)naming-migrations - Migration and index naming conventions<?php
namespace App\Providers;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
Model::preventLazyLoading(!app()->isProduction());
}
}
<?php
use Illuminate\Support\Facades\Cache;
// Cache a query result for 1 hour (3600 seconds)
$popularPosts = Cache::remember('posts:popular', 3600, fn () =>
Post::query()
->withCount('comments')
->orderByDesc('comments_count')
->take(10)
->get()
);
<?php
// Cursor pagination — efficient for infinite scroll and large tables
$posts = Post::query()
->where('published_at', '<=', now())
->orderByDesc('published_at')
->cursorPaginate(15);
<?php
// Instead of loading all posts just to count them
$users = User::withCount('posts')->get();
foreach ($users as $user) {
echo "{$user->name} has {$user->posts_count} posts";
}
<?php
// Memory-efficient processing of large tables
User::query()
->where('last_login_at', '<', now()->subYear())
->chunkById(1000, function ($users) {
foreach ($users as $user) {
$user->update(['status' => 'inactive']);
}
});
<?php
use Illuminate\Support\Facades\DB;
// Keep transactions short and focused
DB::transaction(function () {
$order = Order::create([
'user_id' => auth()->id(),
'total' => $this->calculateTotal(),
]);
$order->items()->createMany($this->cartItems());
$order->user->decrement('credits', $order->total);
});
Read individual rule files for detailed explanations and code examples:
rules/query-eager-loading.md
rules/index-composite-indexes.md
rules/cache-remember.md
rules/_sections.md
Each rule file contains:
For the complete guide with all rules expanded: AGENTS.md
AGENTS.md (opens in a new tab)README.md (opens in a new tab)metadata.json (opens in a new tab)rules/_sections.md (opens in a new tab)rules/_template.md (opens in a new tab)rules/cache-invalidation.md (opens in a new tab)rules/cache-remember.md (opens in a new tab)rules/cache-tags.md (opens in a new tab)rules/cache-ttl.md (opens in a new tab)rules/data-avoid-unbounded.md (opens in a new tab)rules/data-chunk-by-id.md (opens in a new tab)rules/data-cursor-iteration.md (opens in a new tab)rules/data-cursor-pagination.md (opens in a new tab)rules/debug-explain-analyze.md (opens in a new tab)rules/debug-laravel-debugbar.md (opens in a new tab)rules/debug-slow-query-log.md (opens in a new tab)rules/eloquent-query-builder-hot-paths.md (opens in a new tab)rules/eloquent-subquery-selects.md (opens in a new tab)rules/eloquent-where-has-optimization.md (opens in a new tab)rules/eloquent-with-count-aggregates.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
24 skills in this plugin
/api-design-patternsRESTful API design, error handling, versioning, and best practices. Use when designing APIs, reviewing endpoints, implementing error responses, or setting up API structure. Triggers on "design API", "review API", "REST best practices", or "API patterns"./clean-code-principlesSOLID principles, design patterns, DRY, KISS, and clean code fundamentals. Use when reviewing architecture, checking code quality, refactoring, or discussing design decisions. Triggers on "review architecture", "check code quality", "SOLID principles", "design patterns", or "clean code"./code-slopDetect AI-generated code patterns ("slop") in PHP/Laravel and TypeScript/React source — comment narration, generic naming, premature interfaces, defensive overdose, mock-everything tests, and the absence of human "scars". Use when reviewing AI-assisted PRs, auditing code for taste/quality (not metrics — that's technical-debt), or hardening a code-review checklist. Triggers on "review for AI slop", "find AI patterns", "check code feels human", "audit code-quality taste"./asyrafhussin-agent-skills-1:laravel-database-optimizationfrom asyrafhussin-agent-skills-1
asyrafhussin-agent-skills-1@cascade-code-languages-misc-1 is listed by joshuarweaver/cascade-code-languages-misc-1 — review the source before installing
npx claudepluginhub joshuarweaver/cascade-code-languages-misc-1 --plugin asyrafhussin-agent-skills-1Other plugins' skills for the same job