Laravel eloquent

From HoangNguyen0403/agent-skills-standard · View interactive version

Laravel eloquent is an AI agent skill from the GitHub repository HoangNguyen0403/agent-skills-standard. 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.

How to use this skill

Skill file

Laravel Eloquent

**Priority: P0 (CRITICAL)**

Workflow: Add Model with Safe Queries

  1. Define model — Set $fillable, $casts, and relationships.
  2. Enable strict loading — Call Model::preventLazyLoading(!app()->isProduction()) in AppServiceProvider.
  3. Add scopes — Create scopeActive(), scopeVerified() for reusable filters.
  4. Eager-load in queries — Use with() for all relationship access.
  5. Process large datasets — Use chunk() or cursor() instead of get().

Scope + Eager Loading Example

See implementation examples for model scopes, eager loading, and directory structure.

Implementation Guidelines

Query Efficiency & Performance

Query Logic & Scopes

Models & Security

Anti-Patterns

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.