Skillshub laravel-database-expert
Expert patterns for advanced queries, Redis caching, and database scalability. Use when optimizing Laravel queries, implementing Redis caching, or scaling databases. (triggers: config/database.php, database/migrations/*.php, join, aggregate, subquery, selectRaw, Cache)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/laravel-database-expert" ~/.claude/skills/comeonoliver-skillshub-laravel-database-expert && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/laravel-database-expert/SKILL.mdsource content
Laravel Database Expert
Priority: P1 (HIGH)
Structure
config/ └── database.php # Connection & Cluster config app/ └── Http/ └── Controllers/ # Query logic entry points
Implementation Guidelines
Advanced Query Builder
- Complex Joins: Prefer
andjoinSub($subquery, 'alias', ...)
over raw SQL orwhereExists(fn($q) => $q->select(DB::raw(1))...)
for correlated subqueries.whereIn - Subqueries: Use
with aaddSelect
subquery to avoid N+1 issues.DB::raw - Aggregates: Use
,withCount()
, andwithSum()
directly via Eloquent for optimized column-based aggregation.withAvg() - Raw Expressions: Always use
orselectRaw
with bindings; never use string concatenation in raw queries.whereRaw
Caching Strategy (Redis/Memcached)
- Cache-Aside: Utilize
for frequently accessed data (e.g.,Cache::remember('key', $ttl, $closure)
).posts.all - Redis Tagging: Group related keys using
for grouped invalidation.Cache::tags(['posts', 'user:1']) - Invalidation: Call
to clear specific subsets; never useCache::tags(['posts'])->flush()
globally in production.Cache::flush()
Scalability & Infrastructure
- Read/Write Splitting: Configure 'read' and 'write' keys in
mysql/pgsql connections. Laravel automatically routes SELECT to read and INSERT/UPDATE/DELETE to write; no code changes needed.config/database.php - Indices: Ensure correct database indexes are present on all join and aggregate columns.
Anti-Patterns
- No string SQL concatenation: Use bindings or Query Builder.
- No queries in loops: Use subqueries, joins, or aggregates.
- No
: Use tags to target specific cache groups.Cache::flush() - No direct Redis calls: Use Laravel Cache wrappers consistently.