Eloquent

From event4u-app/agent-config · View interactive version

Eloquent is an AI agent skill from the GitHub repository event4u-app/agent-config. Use when writing Eloquent models, relationships, scopes, or queries via Model:: — 'fetch users with their orders'. NOT for PHPStan output, non-Eloquent services, or raw SQL questions.

How to use this skill

Skill file

eloquent

When to use

Use when creating/modifying Eloquent models, relationships, scopes, or writing database queries.

Do NOT use when:

Procedure: Create or modify a model

Step 0: Inspect

  1. Check existing models — match property declarations, cast patterns, relationship style, scope naming.
  2. Check for repositories — some projects use repository interfaces.
  3. Understand the schema — check migrations for column names, types, constraints.
  4. Check for multi-tenancy — which $connection to use?

Step 1: Read attribute access style

Read eloquent.access_style from .agent-settings.yml. Default: getters_setters.

| Value | Inside model | Outside model |

|---|---|---|

| getters_setters | getAttribute() / setAttribute() | Typed getters/setters |

| get_attribute | getAttribute() / setAttribute() | Same |

| magic_properties | $this->column | $model->column |

→ See guideline php/eloquent.md and php-coding rule for full conventions.

Step 2: Build the model

  1. Set $connection, $table, $fillable/$guarded, $casts, $attributes (defaults).
  2. Add typed getters + fluent setters for each attribute (if getters_setters style).
  3. Add relationship getter above each relationship method.
  4. Add scopes for reusable query constraints.
  5. Register Observer via #[ObservedBy] — never use booted().

Step 3: Write queries

Conventions

→ See guideline php/eloquent.md for getter/setter examples, relationship getters, observers, casts.

→ See guideline php/database.md for indexing, transactions, migrations.

Validate

Output format

  1. Model class with typed getters/setters, relationships, and observer
  2. Migration file if schema changes are needed

Gotcha

Do NOT

Auto-trigger keywords

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.