- What is foxbytehq/laravel-backed-enums used for in Laravel?
- It is a utility package for Laravel applications that already use PHP 8.1+ backed enums for domain state such as order status, user roles, or workflow stages. It adds developer-experience helpers like human-readable labels, localization, validation rules, select options, fluent comparisons, and Eloquent-friendly utilities. It is additive and does not impose a schema or runtime architecture, so it fits best in presentation and form-validation layers rather than as a core domain dependency.
- How do I install and apply laravel-backed-enums to an enum?
- Install it with Composer using composer require foxbytehq/laravel-backed-enums, then apply the package trait or interface to the enums where you want the helpers. You will also add translation keys for localized labels and verify the package version against your Laravel and PHP constraints. Keep the enum backed values unchanged so existing database values and API contracts remain stable.
- Which PHP and Laravel versions does laravel-backed-enums support?
- The package targets Laravel applications on PHP 8.1 or newer and is intended for codebases already using backed enums. The exact tested Laravel version range should be confirmed from the package Composer constraints and its CI matrix before adoption. Pin the package version and run your own compatibility tests against the Laravel versions your application actually supports.
- How do I configure translation keys and labels for backed enums?
- You configure localization by defining translation keys for each enum case and following a consistent naming convention across your application. The package is designed to integrate with Laravel's translator, but missing-translation fallback behavior should be tested explicitly in your setup. Document the enum and translation-key conventions so labels stay consistent and are not scattered across the codebase.
- Does laravel-backed-enums work with Eloquent casts and API resources?
- Backed values remain unchanged, so there is no database migration required simply to adopt the package unless you choose to persist localized labels. Localized labels are presentation-layer conveniences, while Eloquent casts, JSON serialization, API resources, and queue payloads should continue to use the underlying backed values. Test these paths in your application because translation and serialization behavior can depend on how your resources and casts are configured.
- Are the fluent enum comparison methods safe across different enum classes?
- The fluent comparison helpers are intended to improve readability when comparing enum cases, but comparing cases from different enum classes should not be treated as a substitute for native strict comparisons. Verify cross-class behavior in tests before relying on fluent methods in shared or generic code. Native strict comparisons remain the safest baseline for critical authorization or workflow decisions.
- Can I use laravel-backed-enums for validation rules and select options?
- Yes, the package provides validation rules and select options as part of its Laravel-friendly helpers, which can simplify form requests, admin filters, and UI dropdowns. Validate the generated options and rule behavior against your Laravel validator version and your expected localization output. Keep validation rules close to the enum conventions so labels and accepted values stay aligned.
- Does laravel-backed-enums support static analysis and IDE autocompletion?
- Static-analysis and IDE support may be limited because the helpers are added through the package's trait or interface, and the assessment flags possible static-analysis gaps. Run PHPStan or Psalm with your existing baseline and confirm that added enum methods are recognized in your IDE before broad adoption. If static analysis is important, isolate package-specific calls behind an internal interface or wrapper.
- Is laravel-backed-enums safe for production or too immature?
- Runtime risk is low because the package is an additive utility layer, but maturity and supply-chain risk are moderate: it is niche, around 44 stars, and likely single-maintainer. MIT licensing gives you a fork or escape hatch, and community-only support means no SLA. A safe approach is a conditional pilot on non-critical enums, with tests for localization, comparisons, validation, and serialization before making it a critical-path dependency.
- What are alternatives to laravel-backed-enums and how do I avoid lock-in?
- Alternatives include native PHP backed enums with your own small trait or helper methods, or other enum utility packages that provide labels and validation helpers. To avoid lock-in, centralize package-specific calls behind an internal interface or trait and avoid spreading fluent methods across the codebase. Keep persisted values and API contracts stable, and maintain a fork or replacement plan under the MIT license if the package stalls.