laravel-eloquent

laravel-eloquent is a skill for Claude Code, Codex from elmochilyas/laraskills. It costs 0 tokens per session (8,812 once invoked), scanned A, original, MIT.

An advanced guide to Eloquent, Laravel's system for working with database records as PHP objects. It covers relationships, query performance, domain-oriented model design, and keeping business logic separate from database code.

In plain words
What is it for?
Use it when designing Eloquent relationships, optimizing queries, structuring domain logic, or building complex Laravel 13 applications.
Why use it?
It helps prevent models from becoming overloaded with unrelated responsibilities. It also addresses complex data relationships and slow or poorly structured queries.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when designing Eloquent relationships, optimizing queries, structuring domain logic, or building complex Laravel 13 applications.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/elmochilyas/laraskills/laravel-eloquent
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add elmochilyas/laraskills --skill laravel-eloquent
Clone the repo
git clone --depth 1 https://github.com/elmochilyas/laraskills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for laravel-eloquent

README.md
[![agentmods](https://agentmods.dev/badge/skills/elmochilyas/laraskills/laravel-eloquent/github.svg)](https://agentmods.dev/skills/elmochilyas/laraskills/laravel-eloquent)
Your own site
<a href="https://agentmods.dev/skills/elmochilyas/laraskills/laravel-eloquent"><img src="https://agentmods.dev/badge/skills/elmochilyas/laraskills/laravel-eloquent/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for laravel-eloquent

Your own site · 80×15
<a href="https://agentmods.dev/skills/elmochilyas/laraskills/laravel-eloquent"><img src="https://agentmods.dev/badge/skills/elmochilyas/laraskills/laravel-eloquent.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 8,812 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.08812
Opus 5 $0.00000 $0.04406
Sonnet 5 $0.00000 $0.01762
Haiku 4.5 $0.00000 $0.00881

Measured 12d ago against content hash 0d4cde092674, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-12, from the pricing page.

Security

Grade A, and why

laravel-eloquent scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/laravel-eloquent/SKILL.md · 1,506 lines

How it starts

The opening of the file, as written. The whole thing — 1,506 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Laravel 13 Expert Skill: Advanced Eloquent Architecture, Performance & Domain Modeling

When to Use

Use this skill when building Laravel 13 applications that require deep Eloquent knowledge: complex relationship mapping, query performance optimization, domain-driven model design, and advanced ORM features. This is the definitive reference for Eloquent beyond simple CRUD.


Core Philosophy

Eloquent Is Not Your Architecture

Eloquent is:

  • ORM (Object-Relational Mapper)
  • Data Mapper Hybrid
  • Query Builder
  • Persistence Layer

Eloquent is NOT:

  • Business Layer
  • Application Layer
  • Domain Layer

Models can contain domain behavior, but infrastructure concerns belong elsewhere. Avoid "Fat Models" that mix unrelated business logic, email sending, API calls, and file generation.

Architecture Flow

Controller (thin — validation, auth, response)
    ↓
Action / DTO (orchestration, type-safe data)
    ↓
Domain Service (business logic)
    ↓
Repository / Query Object / Custom Builder
    ↓
Model / Eloquent (persistence)
    ↓
Database

1. Relationships

General Rules

Always define explicit relationships — never access $post->user_id directly.

// BAD
$userId = $post->user_id;

// GOOD
$post->user;

Always declare return types on relationship methods:

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

public function posts(): HasMany
{
    return $this->hasMany(Post::class);
}

public function roles(): BelongsToMany
{
    return $this->belongsToMany(Role::class);
}

Naming conventions:

  • Singular for single relations: user(), profile(), company(), subscription()
  • Plural for collections: posts(), comments(), roles(), tags()

1.1 Morph Relations (Polymorphic Single)

Use when multiple model types can own a single related model. Best for: comments, media, attachments, activity logs, notifications, likes.

// Comment belongs to Post, Video, or Product
class Comment extends Model
{
    public function commentable(): MorphTo
    {
        return $this->morphTo();
    }
}

class Post extends Model
{
    public function comments(): MorphMany
    {
        return $this->morphMany(Comment::class, 'commentable');
    }
}

class Video extends Model
{
    public function comments(): MorphMany
    {
        return $this->morphMany(Comment::class, 'commentable');
    }
}

Read the full file on GitHub · 1,506 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 12d ago First seen · 1,506 lines · 0 tokens per session scan A 0d4cde092674

Subscribe to this mod's changes

laravel-eloquent is a skill published in the GitHub repository elmochilyas/laraskills (8 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 8,812 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

truss-schema

Ground a database schema change in this application's real structure using Laravel Truss. Use when adding or altering tables, columns, indexes, or foreign keys, when a migration needs to match what is already there, or when you need to know what a migration actually changed. Structure only, never data.

albertoarena/laravel-truss · 63 tokens

laravel-database-optimization

Laravel database optimization patterns. Use when writing Eloquent queries, creating migrations, configuring caching, debugging slow queries, or optimizing database performance. Triggers on tasks involving N+1 queries, indexing, Redis caching, pagination, or database transactions.

AsyrafHussin/agent-skills · 55 tokens

check-batch-processing

Analyzes PHP code for batch processing issues. Detects single-item vs bulk operations, missing batch inserts, individual API calls in loops, transaction overhead.

dykyi-roman/awesome-claude-code · 35 tokens

eloquent-patterns

Eloquent ORM best practices: query builders, scopes, relations, N+1 prevention, batch operations, soft deletes, model events, raw queries when needed. Apply when: writing or reviewing Eloquent queries and model interactions. Activated automatically by laravel-plugin/stack.md as a convention skill for the development…

AratKruglik/claude-sdlc · 68 tokens

laravel-migrations

Use when designing a database schema or managing Laravel 13 migrations — Schema Builder, columns, indexes, foreign keys, or seeders.

fusengine/agents · 32 tokens

laravel-eloquent

Eloquent and query-layer engineering rules for Laravel — eliminating N+1, choosing a pagination strategy, short atomic transactions, casts and scopes on the model, where raw SQL is allowed, and how migrations declare the schema those queries depend on. Use when writing or reviewing Eloquent models, migrations, query…

Foysal50x/skills · 93 tokens