laravel-eloquent
Optimizes Laravel database performance by preventing N+1 issues and enabling strict lazy-loading checks.
Install
mkdir -p .claude/skills/laravel-eloquent && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/11218" && unzip -o skill.zip -d .claude/skills/laravel-eloquent && rm skill.zipInstalls to .claude/skills/laravel-eloquent
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Write performant Eloquent queries with eager loading, reusable scopes, and strict lazy-loading prevention in Laravel. Use when defining model relationships, creating query scopes, or processing large datasets with chunk/cursor.Key capabilities
- →Prevent N+1 query issues
- →Define reusable query scopes
- →Process large datasets efficiently
- →Enforce strict lazy-loading prevention
How it works
It enforces eager loading and strict lazy-loading prevention while providing patterns for reusable query scopes.
Inputs & outputs
When to use laravel-eloquent
- →Prevent N+1 query issues
- →Create reusable query scopes
- →Implement strict lazy-loading prevention
- →Process large datasets without memory exhaustion
About this skill
Laravel Eloquent
Priority: P0 (CRITICAL)
Workflow: Add Model with Safe Queries
- Define model — Set
$fillable,$casts, and relationships. - Enable strict loading — Call
Model::preventLazyLoading(!app()->isProduction())in AppServiceProvider. - Add scopes — Create
scopeActive(),scopeVerified()for reusable filters. - Eager-load in queries — Use
with()for all relationship access. - Process large datasets — Use
chunk()orcursor()instead ofget().
Scope + Eager Loading Example
See implementation examples for model scopes, eager loading, and directory structure.
Implementation Guidelines
Query Efficiency & Performance
- N+1 Prevention: Always use
with()or$withfor relationships. Never access relationship properties in loop without eager loading (N+1 Prevention). - Strict Loading: Call
Model::preventLazyLoading(!app()->isProduction())inAppServiceProvider::boot()to throwLazyLoadingViolationExceptionin local/dev. - Large Datasets: Use
chunk(),lazy(), orcursor()for processing many records without memory issues (Memory Efficiency).
Query Logic & Scopes
- Reusable Scopes: Define
scopeName(Builder $query): Buildermethods in models for reusable query filters. - Chaining: Chain scopes (e.g.,
User::active()->verified()->get()) to keep controllers from duplicating query logic.
Models & Security
- Mass Assignment: Always define
protected $fillablearray; use$request->validated()forModel::create(). - Casting: Use
protected $castsfor dates, JSON, and custom types to ensure data consistency.
Anti-Patterns
- No lazy loading: Eager-load with
with()or$with; never in loops. - No business logic in Models: Move to Services or Actions.
- No raw SQL strings: Use Query Builder or Eloquent methods.
- No
select *: Specify required columns to limit data transfer.
References
When not to use it
- →When lazy loading is explicitly required
Prerequisites
Limitations
- →Requires Laravel Eloquent
- →Strict loading must be enabled in AppServiceProvider
How it compares
It mandates strict lazy-loading prevention in development, catching N+1 issues before they reach production.
Compared to similar skills
laravel-eloquent side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| laravel-eloquent (this skill) | 0 | 2mo | No flags | Intermediate |
| laravel-specialist | 12 | 3mo | No flags | Intermediate |
| laravel-development | 0 | 3mo | No flags | Intermediate |
| laravel-query-builder | 0 | 2mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by HoangNguyen0403
View all by HoangNguyen0403 →You might also like
laravel-specialist
Jeffallan
Use when building Laravel 10+ applications requiring Eloquent ORM, API resources, or queue systems. Invoke for Laravel models, Livewire components, Sanctum authentication, Horizon queues.
laravel-development
monicahq
Expert guidance for Laravel PHP development following best practices, SOLID principles, and Laravel conventions
laravel-query-builder
relaticle
Build filtered, sorted, and included API endpoints using spatie/laravel-query-builder. Activates when working with QueryBuilder, AllowedFilter, AllowedSort, AllowedInclude, or when the user mentions query parameters, API filtering, sorting, includes, or spatie/laravel-query-builder.
Laravel Invite Only
offload-project
Conventions and APIs for the offload-project/laravel-invite-only package — polymorphic invitations, token acceptance, bulk invites, scheduled reminders, and event-driven hooks.
model
JaguarJack
Generate Eloquent model for CatchAdmin module with full CatchModel features.
curd
JaguarJack
Generates complete CRUD module from database table definition. Orchestrates 9 sub-skills. Use when user says "create CRUD", "generate module from table", or provides a table structure.