agentleFS
soden46soden46/syarif-laravel-ai-skills/skills/eloquent-patterns/SKILL.md

eloquent-patterns

Skill4 starsChanged 5 months agoMITView on GitHub

Laravel guidance to keep Eloquent models explicit, query shapes intentional, relationship loading visible, and production data access bounded.

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 8 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Keep models explicit, query shape intentional, and relationship loading visible near the code that renders or returns data.

    line 11
  2. Distinctive:

    Use accessors sparingly for simple derived values.

    line 45
  3. Distinctive:

    Before rendering Blade reports, printable views, exports, or PDFs, explicitly load the relation graph.

    line 51
  4. Distinctive:

    Do not add new relation dependencies inside templates without updating the load list and render tests.

    line 66
  5. Very specific:

    Do not process unbounded production datasets with all() or broad get() calls.

    line 70
  6. Distinctive:

    Keep bounded validation/display values in one source of truth.

    line 82
  7. Distinctive:

    Prefer enums when supported.

    line 84
  8. Distinctive:

    Use config files for deployment-level options and constants for small legacy/model-owned maps.

    line 104
  9. Very specific:

    Use soft deletes with withTrashed() when historical records must remain readable after related reference data is removed from active use.

    line 108
  10. Distinctive:

    Do not use this as a blanket rule for personal data or records subject to hard-delete compliance.

    line 110

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Eloquent Patterns

Keep models explicit, query shape intentional, and relationship loading visible near the code that renders or returns data.

Model Contracts

Models should declare mass-assignment boundaries, casts, and concrete relationship return types.

class Record extends Model
{
    protected $fillable = [
        'owner_id',
        'number',
        'total',
        'issued_at',
        'is_active',
    ];

    protected function casts(): array
    {
        return [
            'issued_at' => 'date',
            'total' => 'decimal:2',
            'is_active' => 'boolean',
            'metadata' => 'array',
        ];
    }

    public function owner(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
}

Use accessors sparingly for simple derived values. Move heavy behavior into Actions or Services.

Relationship Loading

Prevent N+1 queries by eager loading the relations a surface needs.

Before rendering Blade reports, printable views, exports, or PDFs, explicitly load the relation graph.

public function show(Record $record): View
{
    $record->load([
        'owner',
        'items.product',
        'approvals.user',
    ]);

    return view('records.show', ['record' => $record]);
}

Do not add new relation dependencies inside templates without updating the load list and render tests.

Query Volume

Do not process unbounded production datasets with all() or broad get() calls.

Use:

  • paginate() for normal UI/API lists;
  • cursor pagination for large append-only lists;
  • chunkById() or lazyById() when updating rows during iteration;
  • cursor() or lazy collections for streaming;
  • selected columns and indexed filters for high-volume paths.

Bounded Values

Keep bounded validation/display values in one source of truth.

Prefer enums when supported.

enum RecordStatus: string
{
    case Draft = 'draft';
    case Approved = 'approved';
    case Cancelled = 'cancelled';

    public function label(): string
    {
        return match ($this) {
            self::Draft => 'Draft',
            self::Approved => 'Approved',
            self::Cancelled => 'Cancelled',
        };
    }
}

Use config files for deployment-level options and constants for small legacy/model-owned maps.

Historical Data

Use soft deletes with withTrashed() when historical records must remain readable after related reference data is removed from active use.

Do not use this as a blanket rule for personal data or records subject to hard-delete compliance.

Snapshot attributes that must remain true for a historical document.

DocumentLine::create([
    'reference_id' => $reference->id,
    'reference_snapshot' => $reference->only(['code', 'name']),
]);

Store only fields needed for historical correctness and avoid unnecessary sensitive data.

Context Efficiency

Layer: 3 (Implementation)

Load this skill only when models or queries need review. Do not load with unrelated skills. Keep changes minimal: explicit casts, eager-loaded relations, paginated queries, no unbounded all() or broad get() in production paths.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.