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

From

The methods from and tryFrom do not exist on non-backed enums. When you have a non-backed enum where the string value is exactly the same as it's key, but you need from or tryFrom because of some library (like Laravel's validation), this might be useful.

Usage

use Henzeb\Enumhancer\Concerns\From;

enum yourEnum {
    use From;

    case MyEnum;
}

Examples

YourEnum::from('myenum'); // will return YourEnum::MyEnum;
YourEnum::from(0); // will return YourEnum::MyEnum;
YourEnum::from('MyEnum'); // will return YourEnum::MyEnum;
YourEnum::from('Callable'); // will throw error

YourEnum::from(YourEnum::MyEnum); // will return YourEnum::MyEnum;
YourEnum::from(YourOtherEnum::MyOtherEnum); // will throw error


YourEnum::tryFrom('myenum'); // will return YourEnum::MyEnum;
YourEnum::tryFrom('MyEnum'); // will return YourEnum::MyEnum;
YourEnum::tryFrom('DoesNotExist'); // will return null

YourEnum::tryFrom(YourEnum::MyEnum); // will return YourEnum::MyEnum;
YourEnum::tryFrom(YourOtherEnum::MyOtherEnum); // will return null;

Note: Under the hood it uses the Getters functionality, so you can use lower- and uppercase names, and you can also use Mappers that you have defined as described in Defaults.

Warning: Be aware that this feature will not work if you have a backed enum. Even when you use this trait, currently, the original methods take precedence. For those situations use Getters

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.
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
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver