Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Enum Getter

Enum Getter Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Translation-aware helpers for PHP Enums — perfect for Laravel, Laravel Nova, and any application that needs localized enum labels.

Frequently asked questions about Enum Getter
How do I install cable8mm/enum-getter in a Laravel app?
Install it with Composer using composer require cable8mm/enum-getter, then import the enum helpers where you build labels or option arrays. It is a lightweight utility layer over native PHP backed enums rather than a framework extension, so adoption is typically limited to the enums and formatters that need it. Pin to ^2.2 and review the changelog on each minor release.
Does enum-getter support Laravel 9, 10, and 11?
The package is described as fitting Laravel 9, 10, and 11 as well as standalone PHP 8.1+, and the v2.2.0 release is an additive minor with no signaled breaking changes. Before adopting, confirm the Composer constraints against the oldest runtime you deploy, since newer helpers may rely on language features unavailable on older 8.1 patch levels. Existing v2.1.x consumers need no code changes.
How do I get a human-readable label for an enum case?
The package provides getter helpers for cases, values, labels, and key-value arrays, so you call the label helper instead of maintaining a match statement or hardcoded array at each call site. That keeps labels consistent across forms, API resources, and select inputs. Wrapping the calls in a small per-enum trait or class gives you one place to change if conventions shift.
What does fromKey do, and does it throw on an invalid key?
fromKey is the inverse of the existing key lookup: it accepts the stable key and returns the enum instance, closing the round trip needed for request hydration from a form submission. The v2.2.0 notes mention error handling but do not specify whether an unknown key throws, returns null, or falls back, so validate that behavior in a spike before relying on it. If you need non-throwing call sites, check whether a tryFromKey counterpart exists.
Are enum keys stable if I rename a case?
If keys are derived from case names, renaming a case is a silent data-contract break for stored values, cached payloads, and submitted form keys. Treat keys as persisted identifiers and add a documented mapping or data migration whenever a rename is unavoidable. The overview does not promise a key stability guarantee, so keep a per-enum wrapper as your exit ramp.
How is enum-getter different from native Enum::cases() and Laravel Rule::enum?
It complements rather than replaces native features: Enum::cases(), Laravel's enum casting, and Rule::enum continue to handle enumeration and validation. The package adds presentation metadata such as localized labels and key-value arrays for select inputs, API payloads, and form options. If your enums already map one-to-one to display strings, the dependency adds little value.
Can I use enum-getter with Laravel Nova?
Yes. The overview explicitly calls out Laravel Nova as a target use case, since Nova fields and filters often need localized labels and key-value options. Use the package helpers to build option arrays and labels so Nova resource code stays free of hardcoded match statements.
Does enum-getter work outside Laravel, in standalone PHP?
Yes. It is a utility layer over native PHP backed enums and is described as suitable for standalone PHP 8.1+ as well as Laravel. That makes it usable in CLI tools, shared packages, and non-Laravel services that need the same label and key conventions. Check the Composer constraints for the specific PHP version you target.
How should I test fromKey and enum label helpers in my application?
Write a spike test covering a valid key, an unknown key, and a stale form submission so you learn whether fromKey throws or returns null. Also test that renaming a case does not silently change persisted keys. Keep package calls behind a per-enum trait or class so your tests target your wrapper rather than the dependency itself.
Is enum-getter safe for production, and what are the maintenance risks?
It is a low-coupling convenience dependency, not load-bearing infrastructure: it owns no persistence, routing, or container bindings, and it is maintained by a single author with a docs-heavy minor release cadence. Pin to ^2.2, review changelogs on each minor, and isolate usage behind a small helper so you can reimplement a couple of methods locally if the package stalls. The main production risk is semantic ambiguity around invalid-key handling rather than architectural coupling.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource