konekt/enum-eloquent
Laravel Eloquent casting for Konekt Enums. Add the CastsEnums trait and define a $enums map on your model to automatically convert attributes to Enum objects, supporting Konekt Enum 2–4 and Laravel 8–12.
The package integrates seamlessly with Laravel's Eloquent architecture using standard trait-based extension patterns. It leverages existing mutator/attribute casting mechanisms without modifying core framework functionality. Version constraints (Konekt Enum 2.x-4.x with Laravel 8-12) ensure compatibility with modern stacks. The runtime resolution feature (ClassName@method) demonstrates thoughtful design for extensible applications.
Installation is trivial via Composer with minimal code changes required (adding trait and defining $enums). The test coverage via GitHub Actions and active maintenance history indicate reliability. Runtime resolution provides flexibility for library development and multi-tenant scenarios.
Moderate risk due to low adoption (0 dependents) despite 62 stars, suggesting limited real-world validation. Critical concerns include undefined behavior for null database values, unclear handling of enum's __DEFAULT during hydration, and potential data integrity failures when invalid values exist in the database (throws UnexpectedValueException). Dependency on Konekt Enum's stability introduces single-point-of-failure risk. Compatibility with Laravel Nova or other admin panels is undocumented.
Key questions: How does the package handle null database values? Does it respect enum's __DEFAULT automatically during hydration? What is the behavior when enum classes change (e.g., new values added) for existing data? How does it interact with Laravel Nova or admin panels? Are there measurable performance implications for high-volume enum operations (e.g., 10k+ records)?
Ideal for Laravel 8-12 projects using Konekt Enum with PHP 8.0+. Best suited for domain-driven stateful entities (e.g., order statuses, user roles) where type safety and validation are critical. Requires no architectural overhaul—complements existing Laravel patterns. DB columns must be VARCHAR (not DB-level ENUM types) for portability.
Migration path: 1) Install package via Composer, 2) Add CastsEnums trait to models, 3) Define $enums mappings for attributes, 4) Validate existing database values against enum definitions (critical to prevent runtime exceptions), 5) Update code to use enum objects instead of raw strings. For runtime resolution, implement resolver classes with static methods returning enum FQCNs.
Compatibility with Laravel Collective Forms requires the EnumsAreCompatibleWithLaravelForms trait. Works seamlessly with mass assignment and relationship operations. No known conflicts with modern Laravel tooling when used as documented.
Sequencing: Start with non-critical models (e.g., internal admin entities), validate data integrity before rollout, then expand to core domains. Use runtime resolution for reusable components (e.g., packages) to decouple enum implementations from consuming applications.
Low ongoing maintenance burden as it's a trait-based extension with no runtime services. Updates require only version pinning in composer.json. MIT license eliminates licensing concerns but offers no commercial support.
Support relies entirely on GitHub issues and community contributions. Limited adoption (0 dependents) suggests sparse real-world troubleshooting resources—documentation is the primary support channel. Konekt Enum's stability directly impacts this package's reliability.
No significant scaling concerns—attribute casting occurs on-demand during model access with negligible performance overhead. However, unhandled UnexpectedValueException from invalid enum values could cause application crashes during high-traffic operations. Proper error handling (e.g., try/catch around assignments) is critical for production stability.
Ramp-up is minimal for Laravel developers familiar with Eloquent mutators. The core pattern (trait + $enums array) is intuitive, but teams must understand Konekt Enum conventions (e.g., isPending() helpers, value() method). Gotchas like DB column type requirements and form integration nuances require documentation review. Debugging tips (e.g., dd($status->values())) are helpful for onboarding.
How can I help you explore Laravel packages today?