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
->valuewhere 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; noEnumsuffix. - Behaviour lives on the enum. A method on the enum answers a question about a case (
$method->requiresAddress()), never amatchorswitchat 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(), notPeriod::toDateRange($period). - Exhaustive
match, nodefaultarm. A new case then fails loudly withUnhandledMatchErrorin the first test that hits it, instead of silently taking the default. - The display label is
label(). NotgetLabel(). Other per-case values follow suit:remoteValue(), notgetRemoteValue(). - 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).