- How do I install webfox/laravel-backed-enums in a Laravel project?
- Install it with Composer using composer require webfox/laravel-backed-enums, then add the package trait to each backed enum where you want labels, option lists, or comparison helpers. Adoption is lightweight because backed values do not change, so there is no data migration or schema impact.
- Which PHP and Laravel versions does laravel-backed-enums support?
- The package targets PHP 8.1+ native backed enums and is designed for Laravel applications. The exact Laravel version constraints should be checked in composer.json and CI because enum-adjacent behavior has shifted across Laravel majors. Verify the supported PHP and Laravel matrix before adopting it in production.
- How do I add labels to a backed enum using this package?
- Add the package trait to your enum and define the translation key convention the package expects for each case. The label helpers then resolve human-readable text through Laravel's translator, so you can use the labels in Blade, API resources, and form option lists. Set up your per-enum language files or namespaced keys before relying on the labels.
- How does localization work for enum labels in laravel-backed-enums?
- Localization flows through Laravel's existing translator and __() helper rather than a separate mechanism, so labels follow the application locale. You need to establish a translation key convention, such as per-enum language files or namespaced keys, and seed those files. Check the documented behavior for missing translation keys before using it in user-facing output.
- Does webfox/laravel-backed-enums provide validation rules for enum values?
- The package is described as adding Laravel-friendly helpers for labels, option lists, and fluent comparison rather than as a full validation replacement. The technical evaluation flags uncertainty over whether Eloquent casts and validation rules ship out of the box. If no dedicated rule is provided, continue using Laravel's native Rule::enum() alongside the package trait.
- Can I use laravel-backed-enums with Eloquent casts and Form Requests?
- Yes, backed enum values remain unchanged, so existing Eloquent casts and API contracts are unaffected. Use the package's label helpers in API resources, Blade templates, and select inputs while keeping validation in Form Requests. For validation, use Laravel's native enum rule unless the package's API confirms a dedicated rule.
- What comparison methods does the package add to backed enums?
- The package adds fluent comparison helpers such as is() so application code can check enum state without verbose value comparisons. These helpers keep status, role, or state-machine checks readable in domain logic. Confirm the exact method names, signatures, and return types against the package source before depending on them widely.
- Does laravel-backed-enums conflict with BenSampo/laravel-enum or spatie/enum?
- Traits on enums are additive, so you cannot layer two enum packages that both define methods like label() or is(). This package competes for exclusive ownership of the enum behavior surface, so choose one package per enum or wrap vendor behavior behind your own abstraction. Test compatibility if you already use another enum trait.
- Is webfox/laravel-backed-enums production-ready and actively maintained?
- The package has a small adoption base of around 44 stars, which implies a thin bus factor and limited production war stories. The MIT license provides a clean fork escape hatch, which reduces abandonment risk. Before production use, verify test coverage, CI status, static-analysis compatibility, and the maintainer's release cadence.
- How do I generate an option list or select array from an enum?
- Use the package's label and option-list helpers after adding the trait to your enum, which is useful for building select inputs and API payloads. Keep a consistent translation key convention so each case resolves to the correct human-readable label. Verify the exact helper method name and output shape in the package documentation before wiring it into forms.