Skip to content
Back to skills

Laravel Rules

ASecurity

Standing rules for Laravel code covering thin controllers, form requests, policies, Eloquent relations and eager loading, queues, config caching and feature tests.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 26, 2026
ai-agentsrustgophpapidatabase

Works with

  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 26, 2026

npx -y skills add hermes-hq/hodios-dist --skill laravel-rules --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Laravel Rules?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Laravel Rules
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hermes-hq-laravel-rules/badge)](https://www.skillsdirectory.com/skills/hermes-hq-laravel-rules)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: laravel-rules
description: Standing rules for Laravel code covering thin controllers, form requests, policies, Eloquent relations and eager loading, queues, config caching and feature tests.
license: CC0-1.0
metadata:
  version: 1.0.0
  kind: rule
  category: conventions
  source: https://hermes-ide.com/prompts/laravel-rules
  catalog: 2026.1014.1
---

# Laravel rules

Apply these rules to files matching: `app/**/*.php`, `routes/**/*.php`, `config/**/*.php`, `database/**/*.php`, `tests/**/*.php`, `resources/views/**`.

When you write or change code in this Laravel application:

**Know the project first**
- Check the Laravel version in `composer.lock` and follow that version's structure (for example where middleware and exception handling are registered) and the conventions already in this codebase. Use artisan generators (`make:model`, `make:request`, `make:policy`) so files land in the expected places.

**Controllers**
- Keep controllers thin: authorise, take validated input, call domain code, return a response or API resource. Move multi-step business logic into action or service classes (whichever the project already uses).
- Return API responses through API resources, not raw models, so hidden and computed fields are controlled in one place.

**Validation and authorisation**
- Validate input in Form Request classes, and use `$request->validated()` (or `safe()`) to read it. Never pass `$request->all()` to `create` or `update`.
- Authorise with policies and gates: in the Form Request's `authorize()`, with `$this->authorize()` or `can` middleware. Hiding a link is not authorisation.
- Define `$fillable` (or the project's chosen guarding approach) on every model, and never make server-owned fields such as `is_admin`, `user_id` or `price` mass assignable from user input.
- Scope lookups to the current user or tenant (`$request->user()->projects()->findOrFail($id)`), or rely on route model binding with scoped bindings, not a bare `find` on a user-supplied id.

**Eloquent**
- Define relations with return types and use them instead of manual foreign-key queries.
- Eager load every relation a view, resource or loop touches (`with`, `load`, `withCount`). Keep `Model::preventLazyLoading()` enabled outside production if the project has it, and fix violations rather than disabling it.
- Never query inside a loop. Use `whereIn`, `upsert`, `chunkById` or `lazyById` for large sets, and database aggregates instead of counting collections in PHP.
- Wrap multi-step writes in `DB::transaction`. Use the query builder's bindings for all input; never concatenate user input into `DB::raw` or `whereRaw`.
- Back uniqueness rules with unique indexes and relations with foreign keys in migrations. Migrations have a working `down` method or are explicitly irreversible.

**Queues and side effects**
- Put slow or failure-prone work (mail, notifications, third-party calls, exports) in queued jobs implementing `ShouldQueue`. Make jobs idempotent, set `tries`, `backoff` and `timeout`, and handle failure in `failed()`.
- Dispatch jobs and events that depend on a database write after the transaction commits (`afterCommit`).

**Configuration**
- Call `env()` only inside `config/*.php` files. Everywhere else use `config('...')`; once config is cached in production, `env()` outside config returns null.
- Add new settings to a config file with a sensible default and document them in `.env.example`. Never commit `.env` or real secrets.

**Views and output**
- Echo values with Blade's escaped double-brace syntax. Use the raw, unescaped echo only for trusted, already-sanitised HTML, and say why in a comment next to it.

**Tests**
- Write feature tests (Pest or PHPUnit, whichever the project uses) that hit routes, using `RefreshDatabase` and model factories. Fake external effects with `Http::fake`, `Queue::fake`, `Mail::fake` and `Storage::fake`.
- Cover validation errors, the forbidden case for another user, and the happy path for every endpoint you add or change.
- Before finishing, run the tests and the static analysis or formatter the project uses (for example Larastan or Pint).

Files in this skill

  • SKILL.md4 KB
  • agents/openai.yaml269 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.