laravel

A set of architecture and coding rules for Laravel, a PHP framework for web applications. It defines where controllers, actions, services, repositories, models, and other application parts should contain their logic.

In plain words
What is it for?
Use it when designing or changing Laravel controllers, actions, services, repositories, models, jobs, events, commands, database code, and data objects.
Why use it?
It prevents business logic from being scattered across controllers and views, making the application easier to understand and maintain.

Cursor rule

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.

agentmods
npx agentmods add rules/pekral/cursor-rules/laravel
Clone the repo
git clone --depth 1 https://github.com/pekral/cursor-rules
Per session 4,121 This file is loaded in full into every session.
When invoked 4,121 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
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 $0.04121 $0.04121
Opus 5 $0.02060 $0.02060
Sonnet 5 $0.00824 $0.00824
Haiku 4.5 $0.00412 $0.00412

Measured 2d ago against content hash 9f30671cbca1, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

laravel 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 2d 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.

rules/laravel/laravel.mdc · 194 lines

How it starts

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

Architecture

  • Keep business logic out of controllers, middleware, and Blade views.
  • Simple, self-contained domain logic (predicates on the model's own attributes, computed values derived from already-loaded data, simple state derivations that touch nothing else) may live as methods on the Eloquent model itself — see the Database and Eloquent section for the boundary. Anything that needs external services, repositories, model managers, or new database queries goes through an Action.
  • Use Actions for orchestration-heavy use cases.
  • Treat controllers, jobs, events, listeners, and commands as entry points.
  • Entry points must stay slim: validate input, delegate work, return a response.

Layer Responsibilities

  • Controllers: accept validated input, authorize access, delegate work.
  • Actions: orchestrate use cases and business flows.
  • Services: focused stateless domain/application services.
  • Repositories: read-only data access.
  • ModelManagers: write-only persistence.
  • Data Builders: multi-method classes that map, hydrate, or normalize input into DTOs. Not Action pattern — no __invoke(). Never query the database.
  • Eloquent Models: framework boilerplate (relationships, scopes, casts, accessors) plus simple self-contained domain methods on own data — see the Database and Eloquent section for the boundary.
  • Shared Concerns (app/Concerns/): globally shared and reusable logic — typically traits — that is domain-agnostic and consumed across two or more unrelated domains. Never a home for domain-specific code. See the Shared Concerns section below.

Shared Concerns

  • app/Concerns/ is the canonical home for all globally shared and reusable logic in the application — typically traits, but also small reusable helpers and value objects that exist purely to be consumed across unrelated domains.
  • Place a trait or helper in app/Concerns/ only when it is globally applicable (consumed across two or more unrelated domains, layers, or entry points), domain-agnostic (no knowledge of a concrete model, aggregate, feature flow, or business rule), and reusable as-is (consumers use it without further specialization). Validation rule traits are exempt from all three — the Validation section below mandates a trait here for every rule set regardless of consumer count or domain scope.
  • Never put domain-specific logic in app/Concerns/ — anything tied to a concrete model, feature flow, or business rule must live in the relevant business-logic layer under app/{Domain}/. A validation rule trait named for the aggregate it validates is the sanctioned exception: a rule set is a declarative input contract, not business logic.
  • Validation rule traits (see the Validation section below) are one specific worked example of this rule, not the only allowed category.

Read the full file on GitHub · 194 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. 2d ago First seen · 194 lines · 4,121 tokens per session scan A 9f30671cbca1

Subscribe to this mod's changes

laravel is a cursor rule published in the GitHub repository pekral/cursor-rules (6 stars, last pushed 8d ago), licensed MIT. It adds 4,121 tokens to every session, about $0.0206 per session on Opus 5. 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.