agentleFS
wakqasahmedwakqasahmed/skills/skills/laravel/laravel-conventions/SKILL.md

laravel-conventions

Skill2 starsChanged 3 months agoMITView on GitHub

Follow Laravel conventions before adding routes, controllers, models, validation, or background work. Use when working in a Laravel codebase.

  • Reads credentials
  • Deletes or force-pushes

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

21 rules. About 0 are common, 17 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈17

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this when writing or changing Laravel application code.

    line 8
  2. Distinctive:

    Keep controllers thin; introduce service classes only when the project's existing structure or real complexity warrants them.

    line 17
  3. Distinctive:

    Use named routes and route helpers for application links and redirects.

    line 18
  4. Distinctive:

    Check the installed Laravel major version before applying framework structure or API guidance.

    line 19
  5. Distinctive:

    Use explicit fillable or guarded declarations.

    line 23
  6. Distinctive:

    Avoid N+1 queries; eager load relationships in resources and controllers.

    line 25
  7. Distinctive:

    Use database transactions when modifying multiple related records.

    line 26
  8. Distinctive:

    Never let a migration silently truncate or drop data as a side effect of a schema change (e.g.

    line 42
  9. Distinctive:

    Create a Form Request for every non-trivial store/update endpoint.

    line 46
  10. Distinctive:

    Keep rules declarative; extract reusable rules into custom Rule classes.

    line 47
  11. Distinctive:

    Use API Resources to shape public API responses.

    line 52
  12. Distinctive:

    Put authorization in policies and validate every request at the boundary.

    line 54
  13. Distinctive:

    Use feature flags or config values instead of environment checks scattered through code.

    line 60
  14. Distinctive:

    Use queues with retry limits and failed-job handling.

    line 65
  15. Distinctive:

    Keep job classes single-purpose and idempotent where possible.

    line 66
  16. Distinctive:

    Use Horizon for Redis queue visibility and control when it is installed.

    line 67
  17. Very specific:

    Use php artisan make:<type> --no-interaction for all generated classes (models, requests, jobs, policies, migrations) instead of …

    line 71
  18. Distinctive:

    Use model factories and focused feature tests for application behavior.

    line 73
  19. Very specific:

    Run php artisan test --filter=<Name> for affected code.

    line 77
  20. Very specific:

    Run php artisan route:list and php artisan about after structural changes.

    line 78
  21. Very specific:

    Run project linting: vendor/bin/pint --dirty (or duster, or project equivalent).

    line 79

≈ “Common” is an estimate: at least 1 in 5 of the 372,429 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

Laravel Conventions

Use this when writing or changing Laravel application code.

Defaults

  • Inspect existing routes, models, config, tests, and installed Laravel version before choosing a pattern; match established project conventions where they are sound.
  • Eloquent over raw SQL unless the query is too complex for the ORM.
  • Form Request classes for all validation; never inline validate in controllers.
  • config('key') instead of env('KEY') outside config files.
  • Queue jobs (ShouldQueue) for anything slow, external, or async.
  • Keep controllers thin; introduce service classes only when the project's existing structure or real complexity warrants them.
  • Use named routes and route helpers for application links and redirects.
  • Check the installed Laravel major version before applying framework structure or API guidance; Laravel 10, 11, and 12 are not interchangeable.

Models

  • Use explicit fillable or guarded declarations.
  • Define relationships, casts, and scopes on the model.
  • Avoid N+1 queries; eager load relationships in resources and controllers.
  • Use database transactions when modifying multiple related records.

Foreign Keys And Migrations

  • Match the foreign key column's type exactly to the referenced table's primary key type (foreignId for bigIncrements/id(), not a mismatched unsignedInteger).
  • Set an explicit onDelete/onUpdate policy (cascade, restrict, nullOnDelete) — don't leave it at the database default.
  • Index every foreign key column and any column used in a frequent WHERE/JOIN/ORDER BY; verify with php artisan schema:dump or by reviewing the migration diff against the referenced table before merge.
  • Idempotent job handling on retry is covered in Background Work above — apply it to anything a migration or FK change feeds into a queue.

Production Migration Safety

  • Take a database backup immediately before running any migration that drops a column/table, renames a column, or transforms data in place. A destructive migration with no preceding backup is not deployable — document the backup step in the PR or deploy runbook, not just in your head.
  • php artisan migrate refuses to run against an environment where app.env is production unless you pass --force. Treat that prompt as a guardrail, not friction to script around — never bake --force into a deploy step that isn't gated by its own review/approval (CI job, deploy script) that a human or protected pipeline controls.
  • For any migration with meaningful table-lock time (adding an index or column to a large table, an unbounded UPDATE inside a migration) or any downtime-sensitive change, put the app in maintenance mode first: php artisan down --secret=... before, php artisan up after. Prefer php artisan down --render="errors::503" (or a custom view) over a bare 503, and confirm the app supports zero-downtime alternatives (online DDL tools, additive-then-backfill-then-cleanup migrations) before assuming down is required.
  • MySQL DDL (ALTER TABLE, CREATE TABLE, DROP TABLE) is not transactional — unlike PostgreSQL, a failed statement partway through a multi-statement migration can leave the schema partially applied, and Laravel's migration wrapping transaction will not roll back the already-committed DDL. Keep migrations small and single-purpose (one schema change per migration) so a failure is easy to diagnose and the blast radius is one operation, not five.
  • Test the migration's down() locally (php artisan migrate:rollback) before merging, not just up(). Do not ship a migration you can't cleanly reverse; if a migration is genuinely irreversible (e.g. it drops a column with data that isn't recoverable from the backup taken above), leave down() throwing \RuntimeException with a one-line explanation instead of a silent no-op, so a future rollback attempt fails loud instead of pretending to succeed.
  • Never let a migration silently truncate or drop data as a side effect of a schema change (e.g. changing a column type in a way that MySQL will truncate on conversion) without an explicit backup step called out in the PR description or deploy checklist.

Validation

  • Create a Form Request for every non-trivial store/update endpoint.
  • Keep rules declarative; extract reusable rules into custom Rule classes.
  • Authorize inside the request, not the controller.

APIs And Authentication

  • Use API Resources to shape public API responses; do not return models directly.
  • Authenticate first-party API clients with the project's configured guard; use Sanctum only when its token or SPA-cookie model fits the client.
  • Put authorization in policies and validate every request at the boundary.

Configuration

  • Centralize environment access in config files.
  • Cache config in production; never commit .env files.
  • Use feature flags or config values instead of environment checks scattered through code.

Background Work

  • Dispatch jobs for external API calls, emails, exports, and heavy computations.
  • Use queues with retry limits and failed-job handling.
  • Keep job classes single-purpose and idempotent where possible.
  • Use Horizon for Redis queue visibility and control when it is installed; otherwise follow the project's queue monitoring setup.

Generated Files

  • Use php artisan make:<type> --no-interaction for all generated classes (models, requests, jobs, policies, migrations) instead of hand-writing boilerplate.
  • Tests must use disposable storage or a dedicated test database whose name contains test; never staging, production, or shared operational databases.
  • Use model factories and focused feature tests for application behavior.

Verification

  • Run php artisan test --filter=<Name> for affected code.
  • Run php artisan route:list and php artisan about after structural changes.
  • Run project linting: vendor/bin/pint --dirty (or duster, or project equivalent).

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.