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

Enumhancer Laravel Package

henzeb/enumhancer

View on GitHub
Deep Wiki
Context7

Properties

Enums do not support properties. This is due to the simple fact that enums are forbidden to have any form of state. But sometimes you need to store something.

For example, if you use Enumhancer outside a framework with dependency injection and you want to inject a TransitionHook or a Mapper.

Note: Just to follow the rules of PHP, the properties are stored per enum class or globally for all enums and the methods are therefore static.

Usage

use Henzeb\Enumhancer\Concerns\Properties;

enum YourEnum: string {
    use Properties;

    // ..
}

Examples

YourEnum::property('your_property'); // will return null;
YourEnum::property('your_property', 'your_value');
YourEnum::property('your_property'); // will return 'your_value'
YourEnum::property('your_property', 100);
YourEnum::property('your_property'); // will return 100
YourEnum::property('your_property', null);
YourEnum::property('your_property'); // will return null
YourEnum::property('your_property', fn()=>'true');
YourEnum::property('your_property'); // will return callable
YourEnum::property('your_property', new stdClass());
YourEnum::property('your_property'); // will return stdClass() instance

YourEnum::unset('your_property'); // will remove your_property
YourEnum::unsetAll(); // will clear all properties.

Global properties

You can also set global properties.

Henzeb\Enumhancer\Helpers\EnumProperties::global('property', 'your_value');
Henzeb\Enumhancer\Helpers\EnumProperties::clearGlobal(); // clear all global properties
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui