laravel-best-practices

Installation
SKILL.md

Laravel & PHP Best Practices

You already know PHP and Laravel, so skip generic advice. This skill only records the rules that are easy to get wrong and the choices this team wants. It sits on top of the core principles; it doesn't repeat them.

Setup (keep it cheap)

  1. Core principles: if references/coding-principles-and-best-practices/SKILL.md isn't already in this conversation, read it once. It defines precedence, the conflict ranking, the writing workflow and when to ask, the general checklist, Git review scope and the review format. Don't re-read it on later invocations in the same conversation.
  2. Project profile: run php <folder-containing-this-SKILL.md>/scripts/laravel-profile.php <dir-of-the-file-you're-working-on>. It prints the cached profile from <projectRoot>/.agents/laravel-project-profile.md and only re-inspects composer.json/composer.lock, bootstrap/app.php and tooling config when they've changed. Use it instead of opening those files yourself. Skip this step if the profile is already in this conversation and no config has changed.
    • "No composer.json found" → standalone snippet; state the PHP and Laravel versions you assumed.
    • php not on the host PATH → if the project uses Sail or Docker (laravel/sail, compose.yaml/docker-compose.yml), run it as ./vendor/bin/sail php … or inside the app container. Otherwise read composer.json and composer.lock directly, once.
  3. Learn as you go: when you discover a convention the config can't show (layering, naming, error model, test style) or the user corrects you, add one short bullet under ## Learned conventions in the profile. Keep that section under ~15 lines; it's read on every invocation. If the code contradicts a bullet, the code wins: fix or remove the bullet.

The profile file is meant to be committed, so the team shares the learned conventions.

Versions decide the syntax

Write for the lowest PHP version the project allows (the profile states it) and the installed Laravel version (from composer.lock). Use the newest idioms those versions support, and nothing newer. When you're unsure whether a method exists in the installed version, check vendor/laravel/framework instead of guessing.

Version gates evolve quickly. Treat this table as a starting point, not a source of truth: when uncertain, prefer the profile and installed framework source over memory.

Installs
2
First Seen
1 day ago