cable8mm/enum-getter
A lightweight Laravel/PHP package that provides convenient getter helpers for enums, making it easy to retrieve cases, values, labels, and key-value arrays for forms, validation rules, and select inputs. Keeps enum usage clean, consistent, and reusable across Laravel applications.
Architecture fit. cable8mm/enum-getter is a thin utility layer over native PHP backed enums, not a framework extension. It occupies the "presentation metadata for enums" niche — mapping enum cases to stable keys and human-readable labels for select inputs, API payloads, and config-driven lookups. That is architecturally low-coupling: it does not own persistence, routing, or container bindings, so it can sit at the edge of the domain (formatters, view models, API resources) without contaminating domain logic. Fit is good for teams already standardizing on PHP 8.1+ enums and Laravel's native enum casting; poor for teams still on string constants or with an existing enum-presentation convention.
Integration feasibility. High. The v2.2.0 surface is additive: one new method (fromKey) plus documentation. fromKey is the inverse of the existing key lookup — it accepts the stable key (likely the enum case name or a configured key) and returns the enum instance with error handling. That closes the round-trip loop needed for request hydration: form submits key → validate → fromKey() → enum instance → persist via cast. Previously this required hand-rolled match/constant() calls at every call site. Integration effort is an afternoon for a single bounded context, assuming the key derivation matches the package's convention.
Technical risk. Low-to-moderate. Semver minor, no deprecations or breaking changes signaled. The real risks are (a) semantic ambiguity — the release notes say "error handling" without specifying whether invalid keys throw, return null, or silently fall back; that determines whether call sites need try/catch or null checks, and getting it wrong at scale produces 500s on stale form submissions; (b) key stability — if keys are derived from case names, renaming a case is a silent data-contract break for stored values and cached payloads; (c) bus factor — single-maintainer package, docs-heavy release cadence suggests early maturity, so treat it as a convenience dependency rather than load-bearing infrastructure.
Key questions. Does fromKey throw a typed exception or return null/false on unknown keys, and is that behavior configurable? Are keys the raw case names or a separately configured map, and is there a documented stability guarantee? Is there a tryFromKey counterpart for non-throwing call sites? What is the test coverage and minimum PHP/Laravel version matrix? Does it interact correctly with Laravel's Rule::enum validation and ->cast() on models?
Stack fit. Native fit with Laravel 9/10/11 and standalone PHP 8.1+. Works alongside — not instead of — Laravel's built-in enum casting, Rule::enum, and Enum::cases(). The package adds value specifically where you need labels and stable keys decoupled from case names; if your enums are already 1:1 with display strings, this package adds a dependency for little gain.
Migration path. Incremental and reversible. Adopt in one bounded context first — typically the enum with the widest UI surface (status, role, category). Replace ad-hoc match statements and hardcoded label arrays with package calls behind a small application-level helper or trait, so the package is referenced in one place per enum. That indirection is the exit ramp: if the package stalls, you reimplement two methods locally without touching call sites.
Compatibility. Additive minor release; no code changes required for existing v2.1.x consumers. fromKey is new API, so nothing breaks if unused. Confirm the package's PHP/Laravel constraint supports your oldest deployed runtime before adopting — the new method may rely on language features unavailable on older 8.1 patch levels. Pin to ^2.2 and review the changelog on each minor.
Sequencing. (1) Validate fromKey error semantics in a spike test — throw vs. null drives the calling convention. (2) Add a thin per-enum wrapper (trait or dedicated class) exposing options(), label(), and fromKey(). (3) Wire into form requests and API resources for the pilot enum. (4) Add contract tests asserting key stability for every case, so a case rename fails CI rather than production. (5) Only then roll out to remaining enums, in order of UI surface area. (6) Document the key-stability rule in the team's conventions doc before adoption spreads.
Maintenance. Minimal ongoing cost — no migrations, no config publishing required, no runtime services. The maintenance burden is governance rather than operations: enforcing that enum keys are treated as a public contract, and that case renames go through a rename-plus-migration rather than a straight edit. Budget a recurring line item for dependency review, since a single-maintainer package can go quiet without notice.
Support. Upstream support is community/author-driven with no commercial backing; expect GitHub-issue latency, not SLA. Internal mitigation: keep the wrapper layer thin enough that a fork or inline replacement is a half-day task, and avoid spreading direct package calls across the codebase. Assign one engineer as the de facto owner of the enum-presentation convention.
Scaling. Negligible performance footprint — these are in-memory array/map lookups over a fixed, small case set. Scales trivially with request volume and does not warrant caching. The scaling concern is organizational: as enum count and team size grow, inconsistent key conventions become a data-integrity problem across services and stored rows. Centralize the convention early.
Failure modes. Most likely: (1) unhandled exception or null dereference from fromKey when a client submits a deprecated key — mitigate with validation at the boundary and a documented fallback; (2) silent key drift after a case rename, corrupting stored values and cached payloads — mitigate with contract tests and a rename runbook; (3) label changes leaking into API responses consumed by clients — separate display labels from wire values; (4) package abandonment — mitigated by the wrapper indirection; (5) version skew across services pinning different minors — standardize via a shared constraint.
Ramp-up. Very low. A Laravel developer reads the README (now materially improved — three of four PRs are documentation) and is productive within a couple of hours. The non-obvious learning is the key-vs-label distinction, which the v2.2.0 docs explicitly clarify; make that required reading during onboarding. Plan a short team walkthrough of the key-stability rule rather than relying on docs alone, since the failure mode is silent and deferred.
How can I help you explore Laravel packages today?