PHPackages                             cable8mm/enum-getter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cable8mm/enum-getter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cable8mm/enum-getter
====================

This package make Enums simple for making keys, values and combine array including translate function.

v1.7.1(1y ago)04721MITPHPPHP ^8.3CI passing

Since Jan 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/cable8mm/enum-getter)[ Packagist](https://packagist.org/packages/cable8mm/enum-getter)[ Docs](https://github.com/cable8mm/enum-getter)[ RSS](/packages/cable8mm-enum-getter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (1)

Enum-Getter - The simplest way to get the enum values and keys
==============================================================

[](#enum-getter---the-simplest-way-to-get-the-enum-values-and-keys)

[![code-style](https://github.com/cable8mm/enum-getter/actions/workflows/code-style.yml/badge.svg)](https://github.com/cable8mm/enum-getter/actions/workflows/code-style.yml)[![run-tests](https://github.com/cable8mm/enum-getter/actions/workflows/run-tests.yml/badge.svg)](https://github.com/cable8mm/enum-getter/actions/workflows/run-tests.yml)[![Packagist Version](https://camo.githubusercontent.com/2aa4874a9addc544fa3c6d401fe420c7f276c56fd45c5fc623f71a63c5177a9f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6361626c65386d6d2f656e756d2d676574746572)](https://packagist.org/packages/cable8mm/enum-getter)[![Packagist Dependency Version](https://camo.githubusercontent.com/7ede9c1e20e9f4611304d3ef3ecd6760b946733354d717a9abdb2c0297f63dff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6361626c65386d6d2f656e756d2d6765747465722f7068703f6c6f676f3d504850266c6f676f436f6c6f723d776869746526636f6c6f723d373737424234)](https://packagist.org/packages/cable8mm/enum-getter)[![Total Downloads](https://camo.githubusercontent.com/b686219da1d043987608832f17383cc38a5567f40384353e16eb9c3c769e1e7e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6361626c65386d6d2f656e756d2d676574746572)](https://packagist.org/packages/cable8mm/enum-getter/stats)[![Total Stars](https://camo.githubusercontent.com/116b2d1dcfa3fbf05f925d9fe356f86eeda8af2de9730441ad3fb84e16420d85/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f6361626c65386d6d2f656e756d2d676574746572)](https://github.com/cable8mm/enum-getter/stargazers)[![License](https://camo.githubusercontent.com/d4bbc0c7ed3279bbde1876a03bc4ebd6574de1540333eafd2edc86cf2419374c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6361626c65386d6d2f656e756d2d676574746572)](https://github.com/cable8mm/enum-getter/blob/main/LICENSE.md)

This package simplifies working with `Enum`s by providing convenient functionality for handling keys, values, and combined arrays, including a `translate` function.

It is particularly useful for binding enums to `select` or `multiselect` tags in Laravel Nova, allowing you to manage and use translated values effortlessly.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require cable8mm/enum-getter
```

Usage
-----

[](#usage)

It can be used for Laravel Nova like this:

```
use Laravel\Nova\Fields\Badge;

/**
 * @see https://nova.laravel.com/docs/v5/resources/fields#badge-field
 */
Badge::make(__('Status'), 'status')
    ->map(Status::array(value: 'info'))
    ->labels(Status::array()),
```

```
use Laravel\Nova\Fields\Select;

/**
 * @see https://nova.laravel.com/docs/v5/resources/fields#select-field
 */
Select::make(__('Status'), 'status')
    ->options(Status::array())
    ->displayUsingLabels(),
```

```
use Laravel\Nova\Fields\Status;

/**
 * @see https://nova.laravel.com/docs/v5/resources/fields#status-field
 */
Status::make(__('Status'), 'status')
    ->loadingWhen(Status::loadingWhen())
    ->failedWhen(Status::failedWhen())
    ->displayUsing(function ($value) {
        return Status::{$value}->value() ?? '-';
    }),
```

In order to make a Nova factory::

```
// In Nova factory file
public function definition(): array
{
    return [
        'size' => fake()->randomElement(Status::keys()),
    ];
}
```

How to make use in detail
-------------------------

[](#how-to-make-use-in-detail)

```
use Cable8mm\EnumGetter\EnumGetter;

enum Size: string
{
    use EnumGetter;

    case LARGE = 'large';
    case MIDDLE = 'middle';
    case SMALL = 'small';
}

print Size::LARGE->name;         //=> 'LARGE'
print Size::LARGE->key();        //=> 'large'
print Size::LARGE->value;        //=> 'large'
print Size::has('large');        //=> true
print Size::has('larger');       //=> false
print Size::has(value: 'large'); //=> true
print Size::names();             //=> ['LARGE', 'MIDDLE', 'SMALL']
print Size::keys();              //=> ['large', 'middle', 'small']
print Size::values();            //=> ['large', 'middle', 'small']
print Size::array();             //=> ['large'=>'large', 'middle'=>'middle', 'small'=>'small']
print Size::reverse();           //=> ['large'=>'large', 'middle'=>'middle', 'small'=>'small']
print Size::of('LARGE');         //=> Size::LARGE
print Size::from('large');       //=> Size::LARGE
```

When overriding the `value()` method to support non-English values,

```
use Cable8mm\EnumGetter\EnumGetter;

enum Size2: string
{
    use EnumGetter;

    case LARGE = 'large';
    case MIDDLE = 'middle';
    case SMALL = 'small';

    public function value(): string
    {
        return match ($this) {
            self::LARGE => __('large'),     // grand
            self::MIDDLE => __('middle'),   // milieu
            self::SMALL => __('small'),     // petit(e)
        };
    }
}

print Size2::LARGE->name;        //=> 'LARGE'
print Size2::LARGE->key();       //=> 'large'
print Size2::LARGE->value;       //=> 'large'
print Size::has('large');        //=> true
print Size::has('larger');       //=> false
print Size::has(value: 'large'); //=> false
print Size::has(value: 'grand'); //=> true
print Size2::LARGE->value();     //=> 'grand'
print Size2::names();            //=> ['LARGE', 'MIDDLE', 'SMALL']
print Size2::keys();             //=> ['large', 'middle', 'small']
print Size2::values();           //=> ['grand', 'milieu', 'petit(e)']
print Size2::array();            //=> ['large'=>'grand', 'middle'=>'milieu', 'small'=>'petit(e)']
print Size2::reverse();          //=> ['grand'=>'large', 'milieu'=>'middle', 'petit(e)'=>'small']
print Size2::of('LARGE');        //=> Size::LARGE
print Size2::from('large');      //=> Size::LARGE
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Sam Lee](https://github.com/cable8mm)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance44

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Total

7

Last Release

442d ago

PHP version history (2 changes)v1.2.1PHP ^8.1

v1.5.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/c910c874a0263a18f9f976273054cd45faa3ffbcba7891992f4ab52d0656dd93?d=identicon)[Sam Lee](/maintainers/Sam%20Lee)

---

Top Contributors

[![cable8mm](https://avatars.githubusercontent.com/u/2672043?v=4)](https://github.com/cable8mm "cable8mm (30 commits)")

---

Tags

enumgetterlaravelnovaphpenumgettercable8mmenum-getter

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/cable8mm-enum-getter/health.svg)

```
[![Health](https://phpackages.com/badges/cable8mm-enum-getter/health.svg)](https://phpackages.com/packages/cable8mm-enum-getter)
```

###  Alternatives

[myclabs/php-enum

PHP Enum implementation

2.7k227.9M637](/packages/myclabs-php-enum)[dasprid/enum

PHP 7.1 enum implementation

382146.0M11](/packages/dasprid-enum)[spatie/enum

PHP Enums

84529.1M68](/packages/spatie-enum)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49644.8M97](/packages/marc-mabe-php-enum)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[cerbero/enum

Zero-dependencies package to supercharge enum functionalities.

359207.5k2](/packages/cerbero-enum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
