Weave Code
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 Laravel Package

daverandom/enum

daverandom/enum adds a lightweight enum implementation for PHP, providing type-safe sets of named values with strict validation and easy comparison. Useful for replacing magic numbers/strings in domain models, configs, and APIs.

Deep Wiki
Context7

daverandom/enum is a lightweight PHP library for defining and working with enumerations in a consistent, type-safe way. It helps replace fragile “magic strings/ints” with clear, self-documenting enum values, improving readability and reducing bugs.

Designed for small footprints and straightforward integration, it provides a simple API for declaring enums and validating/handling allowed values across your codebase.

  • Define named enum values with a clear, centralized declaration
  • Validate inputs against the set of allowed values
  • Convert between names and underlying scalar values
  • Compare enum instances reliably for equality and intent
  • Keep domain logic cleaner by removing magic constants
Frequently asked questions about Enum
Is daverandom/enum still relevant for Laravel apps since PHP 8.1 introduced native enums?
No, this package is obsolete for Laravel projects. PHP 8.1+ includes built-in enums with better performance, type safety, and maintenance. Using this package adds unnecessary complexity and risks due to its outdated codebase.
What Laravel/PHP versions does daverandom/enum support?
The package was last updated in 2018 and likely targets PHP 7.x. It’s incompatible with modern Laravel (PHP 8.0+), as it lacks updates for newer PHP features, security patches, or Laravel-specific optimizations.
How do I migrate from daverandom/enum to PHP 8.1+ native enums?
Replace the base class with PHP’s native `enum` syntax. For example, swap `class Status extends Enum` with `enum Status { case Active; }`. Native enums support methods, serialization, and backends—features this package lacks.
Are there security risks using daverandom/enum in production?
Yes. The package is unmaintained, meaning unpatched vulnerabilities could expose your app. PHP 8.1+ enums are actively maintained by the PHP core team, offering far greater security and stability.
Can I use daverandom/enum with Laravel’s dependency injection?
Technically possible, but discouraged. The package lacks Laravel-specific features like service provider integration or Facade support. Native enums work seamlessly with Laravel’s container and testing tools.
What alternatives to daverandom/enum exist for Laravel?
For PHP <8.1, consider `myclabs/php-enum` or `spatie/enum`. For PHP 8.1+, use native enums. Laravel packages like `nunomaduro/collision` also provide enum-like functionality for older PHP versions.
Does daverandom/enum work with Laravel’s Eloquent models?
No. The package lacks database integration helpers. Native enums or alternatives like `spatie/enum` support Eloquent casts and database storage out of the box.
How do I test daverandom/enum in Laravel?
Testing is difficult due to the package’s age and lack of documentation. Native enums integrate cleanly with PHPUnit and Laravel’s testing tools, including mocking and assertions for enum values.
Why would anyone still use daverandom/enum in 2024?
There’s no valid reason. The package is unmaintained, incompatible with modern PHP/Laravel, and offers no unique advantages over native enums. It’s a technical debt risk with no community support.
Can I fork and maintain daverandom/enum for my project?
Forking is possible, but not recommended. Upgrading to PHP 8.1+ and using native enums is faster, safer, and future-proof. If you must support older PHP, use a maintained alternative like `myclabs/php-enum`.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport