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

Subset

This allows you to do certain actions on a subset of the enums.

usage

use Henzeb\Enumhancer\Concerns\Subset;

enum yourEnum {

    use Subset;

    case MY_ENUM;
    case MY_OTHER_ENUM;
    case MY_THIRD_ENUM;
}

Examples

of

to get a subset of cases you can use of.

YourEnum::of(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->cases(); // will return [yourEnum::MY_ENUM, yourEnum::MY_OTHER_ENUM]

without

If you just want to single out one or more cases, you can use without.

YourEnum::without(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->cases(); // will return [yourEnum::MY_THIRD_ENUM]

Note: Each method used on of can be used on without

equals

The equals method can come in handy when you need to compare one or more enums against a subset of your enums.

Equals works just like the method in the comparison trait.

YourEnum::of(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->equals(YourEnum::MY_ENUM); // will return true

YourEnum::without(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->equals(YourEnum::MY_ENUM); // will return false

YourEnum::of(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->equals('MY_ENUM'); // will return true

YourEnum::of(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->equals('my_enum'); // will return true

YourEnum::of(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->equals(YourEnum::MY_ENUM, yourEnum::MY_THIRD_ENUM); // will return true

YourEnum::of(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->equals('MY_ENUM', 'my_other_enum'); // will return true

YourEnum::of(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->equals(YourEnum::MY_THIRD_ENUM); // will return false

names

This method returns an array of names of the specified subset.

YourEnum::of(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->names(); // will return ['MY_ENUM', 'MY_OTHER_ENUM']

values

This method returns an array of values of the specified subset.

YourEnum::of(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->values(); // will return ['my_enum', 'my_other_enum']

do

This method allows you call a closure on each item in the subset.

YourEnum::of(
    yourEnum::MY_ENUM,
    yourEnum::MY_OTHER_ENUM
)->do(
    function(yourEnum $enum) {
        print $enum->name.',';
    }); // will print MY_ENUM,MY_OTHER_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.
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