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

spatie/enum

Obsolete: PHP 8.1+ has native enums (recommended). Spatie Enum provides strongly typed, object-based enums for older PHP versions, enabling IDE-friendly static analysis and refactoring. Define enums via @method annotations and call StatusEnum::draft().

View on GitHub
Deep Wiki
Context7
3.13.0
  • Drop PHP 7.4 support
  • Add Stringable interface to enum class - #116
3.12.0
  • Add support for isset() calls to enum ->value und ->label - #109
3.11.1
  • Change attribute for PHP 8.1 compatibility
3.11.0
  • Added support for PHP 8.1
3.10.0
  • Fix from() and tryFrom() methods to do PHP type-juggling (string to integer) - #108
  • Fix tryFrom() method to catch scalar type-errors - #105
3.9.0
  • Add from() and tryFrom() methods to get closer to PHP8.1 native enums - #94
  • Deprecate make() in favor of from() method - #94
  • Add flyweight pattern to return the same enum instance for every call - #94
3.8.0
  • Add cases() method to retrieve all instances of the enum - #79
3.7.2
  • Fix problem with [@readonly](https://github.com/readonly) annotation and annotation parsing libraries - #92
3.7.1
  • Add description to PHPUnit assertion methods - #88
3.7.0
  • Add ability to use a Closure as value/label map - #87
3.6.4
  • Add psalm annotations to seal and lock internals - #85
3.6.3
  • Fix extra whitespaces in enum definition doc-blocks - #86
3.6.2
  • Fix issue with enums not callable within enum classes - #82
3.6.0
  • Add assertIsEnumValue() and assertIsEnumLabel() to \Spatie\Enum\Phpunit\EnumAssertions - #80
3.5.1
  • Fix \Spatie\Enum\Enum php-doc [@property-read](https://github.com/property-read) annotations - #78
3.5.0
  • Add Faker provider to generate random enum instances, values and labels \Spatie\Enum\Faker\FakerEnumProvider - #74
3.4.0
  • Add \Spatie\Enum\Enum::toValues() and \Spatie\Enum\Enum::toLabels() methods - #72
3.3.0
  • Add \Spatie\Enum\Phpunit\EnumAssertions with a default set of assertions - #71
3.2.0
  • Support PHP ^8.0
3.1.2
  • Don't cast value to string when serializing to JSON - #68
3.1.1
  • Throw TypeError if value passed to Enum construct is not string or integer
3.1.0

#64

  • Add missing type-hints and doc-blocks
  • Fix unique values and labels
  • Flag EnumDefinition as internal
3.0.0
  • A complete overhaul of the package, all details are discussed in the PR
2.3.8
  • Fix for static isXyz($value) magic methods tto return false on invalid value - follow up fix to v2.3.3 - #62
2.3.7
  • Fix internal usage of toArray() to allow custom array representations #58
2.3.6
  • Fix the name if it's matched but isn't the same #50
2.3.5
  • Fix for isEqual() and isAny() method doc-tags to accept mixed values
2.3.4
  • Fix for static method call passed to __call within the context of an object
2.3.3
  • Allow passing invalid string values to isEqual() #39
2.3.1
  • Fix protected method calls to allow overrides #37
2.3.0
  • Make \Spatie\Enum\Enumerable::isValidIndex/Name/Value() methods public #36
  • Please note that this could be breaking for custom implementations of the \Spatie\Enum\Enumerable interface.

2.2.0
  • Add \Spatie\Enum\Enum::getAll() method #33
2.1.2
  • Fix calling public non-static methods #32
2.1.1
  • Fix overriden existing public static methods like Enum::toArray() #29
2.1.0
  • Add enum map index and value Enum::MAP_INDEX and Enum::MAP_VALUE #25
2.0.1
  • Improved static analysis support for ::make
2.0.0

A full major rework of the Enum class - we try to list all changes, for more details you can check out the PR and the Issue.

  • Add \Spatie\Enum\Enumerable interface
  • Add \Spatie\Enum\Exceptions\DuplicatedIndexException, \Spatie\Enum\Exceptions\DuplicatedValueException, \Spatie\Enum\Exceptions\InvalidIndexException and \Spatie\Enum\Exceptions\InvalidValueException exceptions
  • Add \Spatie\Enum\Enum->getIndex() method
  • Add \Spatie\Enum\Enum::getIndices() method
  • Add \Spatie\Enum\Enum->getValue() method
  • Add \Spatie\Enum\Enum::getValues() method
  • Rename \Spatie\Enum\Enum::from() to \Spatie\Enum\Enum::make()
  • Rename \Spatie\Enum\Enum::equals() to \Spatie\Enum\Enum::isEqual()
  • Rename \Spatie\Enum\Enum::isOneOf() to \Spatie\Enum\Enum::isAny()
  • Change \Spatie\Enum\Enum->__construct() signature and responsibility - only take index & value and validate them
  • Change \Spatie\Enum\Enum::toArray() return value instead of an array of value => name it returns value => index
  • Drop recursive \Spatie\Enum\Enum::make() support from inside of an unstatic method
  • Drop \Spatie\Enum\Enum::$map in favor of \Spatie\Enum\Enum->getIndex()and \Spatie\Enum\Enum->getValue()
  • Update all methods have strict type checks: index: int and value: string
  • Update all methods are compatible with all required types: index, value, name or instance of Enum
1.1.0
  • Add support for is* checks
1.0.2
  • Support case insensitive enum values (#13)
1.0.0
  • initial release
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