cerbero/laravel-enum
Cerbero Laravel Enum adds type-safe enum classes to Laravel, with validation rules, model casting, and helper methods for labels and values. A clean way to replace scattered constants with organized, reusable enum objects.
Architecture fit. cerbero/laravel-enum is a thin userland layer over PHP 8.1+ backed enums. It composites behaviour onto your enums via a trait (and/or a base enum class), adding convenience APIs: case lookups (fromName, tryFromName), comparison and membership helpers (is, isNot, in, notIn), collection-style transforms (values, names, toArray, cases), metadata/attribute access (labels, descriptions), and selection-list helpers for forms. There is little to no framework plumbing: no service provider surface we depend on, no migrations, no config, no middleware. Architecturally it belongs in the domain/value layer and cannot reach into persistence, HTTP, or queueing — which makes it a low-blast-radius dependency whose worst-case removal is a mechanical refactor rather than a data or infrastructure migration.
Integration feasibility. Composer-installable, MIT-licensed, single-command adoption. Real effort is not installation but the governance decision: deciding which enums adopt the trait, and codifying that convention so the codebase does not end up with a mix of native-enum usages and trait-enhanced usages that behave subtly differently (e.g. ->value vs. ->toArray(), or cases() vs. a helper). A timeboxed spike on two or three representative enums (a status enum with labels, a flags/permissions enum, and an enum already used in an Eloquent cast) will settle feasibility faster than reading the docs.
Technical risk. Three concerns, in order:
Rule::enum() validation, native enum casts on Eloquent, backed-enum route binding, and Enum::cases() cover the majority of day-to-day enum needs. The package's durable value is ergonomics — labels, metadata, membership helpers, select options — not capability we cannot get elsewhere. That reframes the buy/build decision as "is the ergonomic gain worth an extra dependency?"Key questions.
Rule::enum?toJson/->value round-tripping — does serialization remain identical to a plain backed enum?Stack fit. Suitable for Laravel 9/10/11-era applications on PHP 8.1+. It is not a fit for codebases still on PHP 8.0 or earlier (no native enums at all), and it is largely redundant for teams that have already standardised on native enums plus Laravel's built-in validation and casting — in that case, adopt selectively rather than universally.
Migration path. Purely additive and reversible. Nothing in the data layer changes: backed values stay identical, so database columns, API payloads, and cached JSON are unaffected as long as we keep ->value as the serialization contract and treat helper methods as presentation sugar. Migration is per-enum: add the trait, delete hand-rolled label()/options()/toSelect() helpers, run the existing test suite. No dual-write, no backfill, no feature flag needed beyond keeping the change set small.
Compatibility. Verify against: (a) native BackedEnum interfaces and instanceof checks in existing code; (b) Eloquent enum casts and query builder comparisons; (c) JSON resources / API contracts; (d) static analysis (PHPStan/Psalm level) — trait-based magic can degrade inference, so confirm return types still resolve. Also confirm behaviour under Laravel Octane if we run it.
Sequencing.
->value, cases(), validation via Rule::enum).Maintenance. Near-zero runtime maintenance: no config, no migrations, no scheduled work. The real maintenance burden is upgrade-tracking against Laravel majors and the risk that the package stops being updated while our stack moves on. Mitigate by pinning the version in composer.json, keeping a short internal note on "what we use it for" (so a future fork is a two-hour job, not an archaeology project), and never letting it become load-bearing for persistence semantics.
Support. Upstream support is effectively one person, best-effort, via GitHub issues. We should not place it on a critical path where an unanswered issue blocks a release. Internal ownership should be assigned to the backend guild with a named secondary — the same treatment as any small OSS utility.
Scaling. Negligible performance profile: enum case resolution is in-memory, and any static caching the package does is a small win rather than a risk, provided we validate behaviour under long-running processes (Octane/queue workers) where a cache populated pre-deploy could persist. Verify this during the spike; if it is a concern, it is a deployment-restart policy issue, not a package defect.
Failure modes.
composer update blocked by a version constraint. Response: fork under our org (MIT permits it) or replace with native equivalents.cases(). Response: assert contracts in unit tests, especially ordering used for UI dropdowns.Ramp-up. Low: an engineer familiar with PHP enums is productive in under an hour; the API is small and discoverable. Budget a short internal write-up ("which methods we use, which we deliberately don't") so the team converges on one idiom instead of five. Total onboarding cost is a fraction of a day — the decision cost, not the learning cost, is what deserves management attention.
How can I help you explore Laravel packages today?