AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Laravel Database Optimization

skill-asyrafhussin-agent-skills-laravel-database-optimization · by AsyrafHussin

Laravel database optimization patterns. Use when writing Eloquent queries, creating migrations, configuring caching, debugging slow queries, or optimizing database performance. Triggers on tasks involving N+1 queries, indexing, Redis caching, pagination, or database transactions.

No reviews yet
0 installs
38 views
0.0% view→install

Install

$ agentstack add skill-asyrafhussin-agent-skills-laravel-database-optimization

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-asyrafhussin-agent-skills-laravel-database-optimization)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
4mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Laravel Database Optimization? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Laravel Database Optimization

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.

Metadata

  • Version: 1.1.0
  • Framework: Laravel 13.x
  • PHP: 8.3+

When to Apply

Reference these guidelines when:

  • Writing Eloquent queries or using the query builder
  • Diagnosing and fixing N+1 query problems
  • Adding database indexes to migrations
  • Implementing Redis or cache-based optimizations
  • Paginating or processing large datasets
  • Wrapping operations in database transactions
  • Creating or modifying migrations for production databases
  • Debugging slow queries with EXPLAIN or Laravel Debugbar

Rule Categories by Priority

| 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- |

Quick Reference

1. Query Performance & N+1 (CRITICAL)

  • query-eager-loading - Use eager loading to eliminate N+1 queries
  • query-prevent-lazy-loading - Prevent lazy loading in development
  • query-auto-eager-loading - Configure automatic eager loading on models
  • query-select-columns - Select only needed columns instead of SELECT *

2. Indexing Strategies (CRITICAL)

  • index-foreign-keys - Index all foreign key columns
  • index-composite-indexes - Create composite indexes for multi-column queries
  • index-covering-indexes - Use covering indexes for read-heavy queries
  • index-full-text - Use full-text indexes for search functionality

3. Eloquent Optimization (HIGH)

  • eloquent-query-builder-hot-paths - Use query builder for performance-critical paths
  • eloquent-with-count-aggregates - Use withCount instead of loading relations to count
  • eloquent-subquery-selects - Use subquery selects to avoid extra queries
  • eloquent-where-has-optimization - Optimize whereHas with whereIn subqueries

4. Caching with Redis (HIGH)

  • cache-remember - Use Cache::remember for expensive queries
  • cache-invalidation - Invalidate cache on model changes
  • cache-tags - Use cache tags for group invalidation
  • cache-ttl - Set appropriate TTL values for cached data

5. Pagination & Large Datasets (HIGH)

  • data-cursor-pagination - Use cursor pagination for large datasets
  • data-chunk-by-id - Process large datasets with chunkById
  • data-cursor-iteration - Use lazy cursors for memory-efficient iteration
  • data-avoid-unbounded - Never use unbounded queries on large tables

6. Transactions & Locking (HIGH)

  • lock-short-transactions - Keep transactions short and focused
  • lock-deadlock-retry - Implement deadlock retry logic
  • lock-pessimistic-locking - Use pessimistic locking for critical updates

7. Migrations (HIGH)

  • migrate-zero-downtime - Write zero-downtime migrations
  • migrate-concurrent-indexes - Create indexes concurrently in production
  • migrate-safe-column-additions - Add columns safely without locking tables

8. Query Debugging (MEDIUM)

  • debug-explain-analyze - Use EXPLAIN ANALYZE to understand query plans
  • debug-laravel-debugbar - Use Laravel Debugbar to find query bottlenecks
  • debug-slow-query-log - Enable and monitor slow query logs

9. Naming & Structure (HIGH)

  • naming-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

Essential Patterns

Prevent Lazy Loading in Development

isProduction());
    }
}

Cache Expensive Queries with Redis


    Post::query()
        ->withCount('comments')
        ->orderByDesc('comments_count')
        ->take(10)
        ->get()
);

Cursor Pagination for Large Datasets

where('published_at', 'orderByDesc('published_at')
    ->cursorPaginate(15);

Aggregate Counts Without Loading Relations

get();

foreach ($users as $user) {
    echo "{$user->name} has {$user->posts_count} posts";
}

Process Large Datasets with chunkById

where('last_login_at', 'subYear())
    ->chunkById(1000, function ($users) {
        foreach ($users as $user) {
            $user->update(['status' => 'inactive']);
        }
    });

Short Database Transactions

 auth()->id(),
        'total' => $this->calculateTotal(),
    ]);

    $order->items()->createMany($this->cartItems());

    $order->user->decrement('credits', $order->total);
});

How to Use

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:

  • YAML frontmatter with metadata (title, impact, tags)
  • Brief explanation of why it matters
  • Bad Example with explanation
  • Good Example with explanation
  • Laravel 13 and PHP 8.3 specific context and references

References

Full Compiled Document

For the complete guide with all rules expanded: AGENTS.md

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.