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.
fromKey, closing the round-trip gap between storing an enum key (DB column, API payload, config value) and hydrating the corresponding enum case. This supports a single convention for keys vs. labels instead of scattered match/switch blocks in controllers, resources, and form requests.fromKey with explicit error handling makes invalid-key handling a deliberate decision (validate-and-reject vs. fallback) rather than an implicit null.EnumHelper trait; if you have one or two enums, native enum methods plus Laravel’s enum casting are likely sufficient.key => label) where enums drive UI options.fromKey method plus documentation clarifying the keys-vs-labels distinction and native enum methods. Non-breaking from v2.1.1; safe to adopt on the next maintenance window.Adopt when:
fromKey-style reverse lookup with explicit failure behavior for untrusted input (request payloads, imported files, DB rows written by older code).Look elsewhere or defer when:
cases(), from(), and tryFrom() cover most of it.For executives: This is a small utility that removes repetitive glue code around PHP enums and makes status/type values consistent between what we store, what our APIs return, and what customers see in labels. v2.2.0 adds a safer way to turn a stored key back into an enum value with explicit error handling — reducing silent failures when data or user input is malformed. Risk is low: it is an additive minor release with no breaking changes, and the dependency footprint is minimal. Recommendation: pilot on a couple of enums, confirm it removes boilerplate, then standardize.
For engineering: v2.2.0 introduces fromKey for reverse lookup with error handling, plus clarified docs on the key-vs-label distinction and native enum methods. This lets us store stable keys, render labels at the edge, and make invalid-key handling explicit instead of implicit. It complements Laravel’s native enum casting rather than replacing it. Upgrade is non-breaking from v2.1.1. Before broad adoption, sanity-check supported PHP/Laravel versions and test coverage given the single-maintainer project.
How can I help you explore Laravel packages today?