laravel-enums

Installation
SKILL.md

Laravel Enums

An enum is the one definition of a fixed set of values: a status, a type, a queue name, a permission. Anything the code needs to know about a case — its label, how it behaves, what an external system calls it — is answered by the enum, so call sites ask the case instead of switching on it.

Rules

  • Backed, whenever the value leaves PHP. An enum that's persisted, validated, serialised or sent to a frontend is backed (enum ShippingMethod: string), so its stored form is explicit and stable. A pure enum is fine only for an internal discriminator that never leaves the process, such as the outcome type inside a result object.
  • PascalCase cases, kebab-case string values. case NextDay = 'next-day'. When an external system dictates the values, use its values verbatim and keep the case names PascalCase. Permission values are the one exception, '{verb} {subject}' (laravel-policies).
  • Every fixed identifier is an enum. Queue names, permissions, flash message types, rate-limiter names. Pass ->value where an API wants a string. A typo becomes an error, and every use is one "find usages" away.
  • Named for what it is, in app/Enums/. OrderStatus, ShippingMethod; no Enum suffix.
  • Behaviour lives on the enum. A method on the enum answers a question about a case ($method->requiresAddress()), never a match or switch at the call site. Otherwise every caller repeats the mapping, and a new case has to be hunted down in all of them.
  • Instance methods, not statics taking self. $period->dateRange(), not Period::toDateRange($period).
  • Exhaustive match, no default arm. A new case then fails loudly with UnhandledMatchError in the first test that hits it, instead of silently taking the default.
  • The display label is label(). Not getLabel(). Other per-case values follow suit: remoteValue(), not getRemoteValue().
  • Predicates are real methods. A case callers often ask about gets one written out (isClickAndCollect()), never left to a magic __call, so static analysis sees it.
  • A status with transition rules or side effects is a state machine, not an enum. When moving from one value to another has preconditions, or triggers work, use a state machine (laravel-state-machines). An enum fits a status whose values can be set freely. On an event-sourced aggregate the state is an enum, because the aggregate is the state machine (laravel-event-sourcing).

Example

Installs
55
GitHub Stars
15
First Seen
Mar 27, 2026