- What is emreyarligan/enum-concern used for?
- It is a lightweight PHP/Laravel package that provides an EnumConcern trait for enums. The trait adds helpers for labels, values, options, validation rules, and select arrays so enums are easier to use in forms, APIs, and Blade views. It fits as a thin convenience layer rather than a replacement for Laravel's native enum or casting support.
- How do I install enum-concern in a Laravel project?
- Install it with Composer using composer require emreyarligan/enum-concern. Then add the EnumConcern trait to the enums where you want the helper methods. No migrations or custom bootstrapping are implied by the package's role, but check the README for any release-specific setup.
- Which Laravel and PHP versions does enum-concern support, and is it maintained?
- Compatibility is defined by the package's composer.json constraints for PHP and illuminate/support, so check those before upgrading Laravel or PHP. Check Packagist and GitHub for release activity, because maintenance risk for a small single-purpose package is mostly about whether your Laravel major is covered. Pin a version and review releases before adopting patches broadly.
- How do I get labels, values, and options from an enum with EnumConcern?
- Apply the EnumConcern trait to your enum and call its helper methods for labels, values, and options. These helpers are intended to return collection-friendly or array-friendly representations for forms, APIs, and Blade. Keep the enum cases as the single source of truth and let the trait derive the presentation data.
- Can enum-concern generate Laravel validation rules from an enum?
- Yes, the package advertises validation rule helpers as part of the EnumConcern trait. Use them where you would normally hand-write an in rule or a Rule::enum setup, and confirm the exact method name in the README for your installed version. This keeps validation values aligned with the enum cases.
- How do I build a select array for a Blade form from a PHP enum?
- Use the trait's options or select-array helper to turn enum cases into key/value pairs suitable for Blade select partials. That avoids duplicating labels and values in views or controllers. For API responses, the same helper can produce a consistent payload for front-end selects.
- What changed in enum-concern 1.0.7 for fromValue?
- Version 1.0.7 is described as an additive enhancement that lets fromValue accept custom method-based matching in addition to its previous resolution behavior. The new capability is opt-in, so existing scalar-based calls should continue to use the prior path. Review the changelog and diff to confirm the exact matcher contract and no-match behavior before adopting it widely.
- How does custom matcher precedence work in enum-concern fromValue?
- The technical assessment flags precedence between default and custom matching as a contract that must be defined and tested rather than assumed. When multiple matchers could resolve the same input, add explicit tests for ordering and for the no-match case. Confirm the implementation's throw-versus-null behavior in the source or changelog before relying on it in hydration paths.
- Is enum-concern 1.0.7 backwards compatible with existing fromValue calls?
- The release is presented as a 1.0.x patch with additive, opt-in matching, so callers passing scalars should hit the previous path. That is a strong signal but not a guarantee, so verify it against the changelog and diff and run your existing test suite after pinning ^1.0.7. Leave existing scalar call sites untouched during the first upgrade pass.
- How should I test EnumConcern, and what are alternatives if I do not want another package?
- Use PHPUnit or Pest to assert the trait's labels, values, options, validation rules, and select arrays against the enum cases. Add coverage for fromValue with scalar inputs and, if you adopt 1.0.7 matchers, for custom matcher success, ambiguity, and no-match behavior. If you prefer no extra dependency, hand-written enum helpers or Laravel's native enum casting and Rule::enum can cover some use cases. The trade-off is convenience and consistency versus one more package to maintain.