Weave 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

Extractor

Sometimes you have a piece of text that contains an enum value that you want to use. With this you can simply pass a multiline string and extract all enums that are mentioned by value.

Note: This also works with Mappers, you can either pass along a mapper as second parameter or use the Mapperstrait in case you need the default mapper feature.

Usage

use Henzeb\Enumhancer\Concerns\Extractor;

enum YourEnum: string {
    use Extractor;

    case ENUM = 'enum';
    case ENUM2 = 'another enum';
}

enum YourOtherEnum: int {
    use Extractor;

    case ENUM = 0;
    case ENUM2 = 1;
}

Examples

YourEnum::extract('you can find another enum here'); // returns [YourEnum::ENUM2]
YourEnum::extract('A lot of text with (enum)'); // returns [YourEnum::ENUM]
YourEnum::extract('another enum (enum)'); // returns [YourEnum::ENUM2, YourEnum::ENUM]
YourEnum::extract('extract case sensitive another ENUM') // returns [YourEnum::ENUM2];
YourEnum::extract('contains multiple enums') // returns [];

YourOtherEnum::extract('I found 1 truth'); // returns [YourOtherEnum::ENUM2]
YourOtherEnum::extract('has 1 truth 0 lies'); // returns [YourOtherEnum::ENUM2, YourOtherEnum::ENUM]
YourOtherEnum::extract('I found 100 lies'); // returns []

Note: You can use Mappers in combination with Extractor. This might be helpful when the source has multiple or different notations of your enum cases.

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.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator