PHPackages                             suleymanozev/laravel-enum-helper - 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. suleymanozev/laravel-enum-helper

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

suleymanozev/laravel-enum-helper
================================

Simple opinionated framework agnostic PHP 8.1 enum helper for Laravel

v3.0.0(6mo ago)0233MITPHPPHP ^8.1CI passing

Since Jan 23Pushed 6mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (11)Versions (4)Used By (0)

Laravel Enum Helper
===================

[](#laravel-enum-helper)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fb97fa5c3937ac1a9ec93503ff51df73e0da617e9cd30e3b51c9b6e408663291/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73756c65796d616e6f7a65762f6c61726176656c2d656e756d2d68656c7065722e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/suleymanozev/laravel-enum-helper)[![Pest Tests number](https://camo.githubusercontent.com/08283c2065603fac4b8a78d411f7c77242011824e6f1119f97e741c2fbe17ce7/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d2532337465737473266d6573736167653d393026636f6c6f723d464638384641267374796c653d666f722d7468652d6261646765266c6f676f3d646174613a696d6167652f706e673b6261736536342c6956424f5277304b47676f414141414e5355684555674141414277414141416343414d414141424630792b6d414141426956424d564555414141442f69507639795033586d2b6a2f6d502f2f7766566a36374a653662502f682f70567836703631373564353757517963662b69506e2f695072736e657a417264332b742f7170764e4a64364c502f6a5070753672762f6c50722f6b5070633537542f7276746335374e7036726a336f506c3337634c2f74666e2f77763964366272582f2f4c2f672f72596e2b6e2f677672576d2b6469364c582b6a5072736b6647577a4d707436626c6e3462646435374a6b364c575379636a2b76507175774e566f36726465366250376e7676596e75703931622f2b7666762f6c76746335374f71764e544673392f2f742f746435374c39742f722f69507064364c506170656a2f6f76703236627879363776396c666c64364c4a72344c6a777376622f7876332f6a7633397a76317436627547356354447265483569766c6335724a7936373656346378623537442f792f6835304d4f79344f4355786356613737582f69507065364c502f6a502b7075394c38742f2f2f7476755179636641724e7870364c7a41726431353172372f692f396e3462622f6a2f39653672542f69667237696672736b764c596e7568693837746738626c673762662f76762f2f6c502b77784e746a3962332f71762f2f6f502f2b69767a2f6c2f7238696672796e2f66766c505466705044656f66444b74756a48744f5758314e462f3473654333635238327346753763426f354c694d77504d724141414157485253546c4d412f577638464149432f644d452f576a2b337445472f507637393847316f48526a53306b314c4273574467734a2f7633362b66547938657a6e342b4c683239584e7a4d7a4c79734c41774c53777236366f704a71616b592b4e69344a37656e643062476c7059313158553034384b69636d49523866697a6c2b767741414156644a524546554b4d39747a325658416c4551674f4642425552706b453637753775374531594659516c31536276726c7a7444694c7673732b66632f6643656d584d76414568684b71553735395031724c6f7855445579456839665048307a37414c69567245592b53534e74784e533275706f75597637684f4c313931614b56735a48555467626e51505167446b7134637448646f516d54576d573457467a6c56554456704e4b58663266577057625a497755712f68636d6a5747596e536131705a5a6a456f6f6d72456456416973443743583647456234307271544f4478436a32314f6a444f766a5256386c326a68756442446368672f46556244495a4349547a775179483661392b32414d44626d3947666c74466e786741647451575567514a6c345651713337755063536e7366595a7a61763645773138665134665559504d37516e34755369496479783573614a36542b2f332b354b536c7473686963774932557066414b452f616f415254766e6e374b4d594d646c41557957525379484e324a65553432486c43693454737a5448636d756a33694d566450354a7a6f7941574e7a693654335a47724d46436c694b334241715253432f42322b3649787659594e634f2b324e7066762b79466931304c66425541414141415355564f524b35435949493d)](https://github.com/suleymanozev/laravel-enum-helper/tree/main/tests)[![GitHub Tests Action Status](https://camo.githubusercontent.com/93680a467f49887a315835965d85c4dd4af04b551949f95cf1ddf9794cc47388/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73756c65796d616e6f7a65762f6c61726176656c2d656e756d2d636f6c6c656374696f6e732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d746573747326636f6c6f723d354645384233267374796c653d666f722d7468652d6261646765266c6f676f3d646174613a696d6167652f706e673b6261736536342c6956424f5277304b47676f414141414e5355684555674141414277414141416343414d414141424630792b6d414141426956424d564555414141442f69507639795033586d2b6a2f6d502f2f7766566a36374a653662502f682f70567836703631373564353757517963662b69506e2f695072736e657a417264332b742f7170764e4a64364c502f6a5070753672762f6c50722f6b5070633537542f7276746335374e7036726a336f506c3337634c2f74666e2f77763964366272582f2f4c2f672f72596e2b6e2f677672576d2b6469364c582b6a5072736b6647577a4d707436626c6e3462646435374a6b364c575379636a2b76507175774e566f36726465366250376e7676596e75703931622f2b7666762f6c76746335374f71764e544673392f2f742f746435374c39742f722f69507064364c506170656a2f6f76703236627879363776396c666c64364c4a72344c6a777376622f7876332f6a7633397a76317436627547356354447265483569766c6335724a7936373656346378623537442f792f6835304d4f79344f4355786356613737582f69507065364c502f6a502b7075394c38742f2f2f7476755179636641724e7870364c7a41726431353172372f692f396e3462622f6a2f39653672542f69667237696672736b764c596e7568693837746738626c673762662f76762f2f6c502b77784e746a3962332f71762f2f6f502f2b69767a2f6c2f7238696672796e2f66766c505466705044656f66444b74756a48744f5758314e462f3473654333635238327346753763426f354c694d77504d724141414157485253546c4d412f577638464149432f644d452f576a2b337445472f507637393847316f48526a53306b314c4273574467734a2f7633362b66547938657a6e342b4c683239584e7a4d7a4c79734c41774c53777236366f704a71616b592b4e69344a37656e643062476c7059313158553034384b69636d49523866697a6c2b767741414156644a524546554b4d39747a325658416c4551674f4642425552706b453637753775374531594659516c31536276726c7a7444694c7673732b66632f6643656d584d76414568684b71553735395031724c6f7855445579456839665048307a37414c69567245592b53534e74784e533275706f75597637684f4c313931614b56735a48555467626e51505167446b7134637448646f516d54576d573457467a6c56554456704e4b58663266577057625a497755712f68636d6a5747596e536131705a5a6a456f6f6d72456456416973443743583647456234307271544f4478436a32314f6a444f766a5256386c326a68756442446368672f46556244495a4349547a775179483661392b32414d44626d3947666c74466e786741647451575567514a6c345651713337755063536e7366595a7a61763645773138665134665559504d37516e34755369496479783573614a36542b2f332b354b536c7473686963774932557066414b452f616f415254766e6e374b4d594d646c41557957525379484e324a65553432486c43693454737a5448636d756a33694d566450354a7a6f7941574e7a693654335a47724d46436c694b334241715253432f42322b3649787659594e634f2b324e7066762b79466931304c66425541414141415355564f524b35435949493d)](https://github.com/suleymanozev/laravel-enum-helper/actions/workflows/run-tests.yml)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/6f5257791e186d3dd91141a7821812fea3e7a416cdec1b9eeee08032cf568732/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73756c65796d616e6f7a65762f6c61726176656c2d656e756d2d68656c7065722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6c6162656c3d636f64652532307374796c6526636f6c6f723d354645384233267374796c653d666f722d7468652d6261646765)](https://github.com/suleymanozev/laravel-enum-helper/actions/workflows/php-cs-fixer.yml)[![Total Downloads](https://camo.githubusercontent.com/a25c13ffc3573545ccf7dcfc785ab8335f3fcd21cfa5d7547f07c6792faef2fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73756c65796d616e6f7a65762f6c61726176656c2d656e756d2d68656c7065722e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/suleymanozev/laravel-enum-helper)

This is an extension of the [suleymanozev/enum-helper](https://github.com/suleymanozev/enum-helper) package based on Laravel Framework. The package consists on a `LaravelEnumHelper` trait that extends `EnumInvokable`, `EnumFroms`, `EnumNames`, `EnumValues`, `EnumEquality`, `EnumDescription` and add dynamic methods to return a translation or "property" method and relative helper methods.

You can think about it as an [`EnumDescription` trait](https://github.com/suleymanozev/enum-helper#descriptions-and-translations) but completely dynamic.

So you can define a custom `method()` and have these functions available: `[method]s()`, `[method]sByName()`, `[method]sByValue()`. For example with `color()` you obtain `colors()`, `colorsByName()`, `colorsByValue()` methods.

The cool thing is you can also avoid writing the method and write only the translations. For example, you can define the property `excerpt` by writing only the translations on enums.php [(see below for explanation)](#translations)and obtain `excerpt()`, `excerpts()`, `excerptsByName()`, `excerptsByValue()` methods.

The package use the [Laravel `Pluralizer` component](https://laravel.com/docs/localization#pluralization-language) to get the singular method to call or to translate.

The `enum-helper` base package summary
--------------------------------------

[](#the-enum-helper-base-package-summary)

You should see the `suleymanozev/enum-helper` details on his [repository](https://github.com/suleymanozev/enum-helper), this is a summary:

- **Invokable cases**: get the value of enum "invoking" it statically
- **Construct enum by name or value**: `from()`, `tryFrom()`, `fromName()`, `tryFromName()` for all enums
- **Enums Inspection**: `isPure()`, `isBacked()`, `has()`, `hasName()`, `hasValue()` methods
- **Enums Equality**: `is()`, `isNot()`, `in()`, `notIn()` methods
- **Names**: methods to have a list of case names (`names()`, `namesByValue()`)
- **Values**: methods to have a list of case values (`values()`, `valuesByName()`)
- **Unique ID**: get an unique identifier from instance or instance from identifier (`uniqueId()`, `fromUniqueId()`)
- **Descriptions &amp; Translations**: add description to enum with optional translation (`description()`,`descriptions()`,`descriptionsByName()`,`descriptionsByValue()`)

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

[](#installation)

Laravel 8 or above and PHP 8.1+ are required.

```
composer require suleymanozev/laravel-enum-helper
```

Usage
-----

[](#usage)

You can use this functionality simply using the `LaravelEnumHelper` trait.

```
use Suleymanozev\LaravelEnumHelper\LaravelEnumHelper;

// Pure enum
enum Status
{
    use LaravelEnumHelper;

    case PENDING;
    case ACCEPTED;
    case DISCARDED;
    case NO_RESPONSE;

    public function color(): string
    {
        return match ($this) {
            self::PENDING => '#000000',
            self::ACCEPTED => '#0000FF',
            self::DISCARDED => '#FF0000',
            self::NO_RESPONSE => '#FFFFFF',
        };
    }
}

// BackedEnum
enum StatusString
{
    use LaravelEnumHelper;

    case PENDING = 'P';
    case ACCEPTED = 'A';
    case DISCARDED = 'D';
    case NO_RESPONSE = 'N';

    // or public function color(?string $lang = null): string
    public function color(): string
    {
        ...
    }
```

After that you can define a custom "property" method like `color()` or `color(?string $lang = null)` or define the translations instead.

Translations
------------

[](#translations)

Using this trait there is 2 way to manage translation strings.

### Using Short Keys

[](#using-short-keys)

Language strings may be stored in `enums.php` files within the `lang` directory. Within this directory, there may be subdirectories for each language supported by the application.

```
/lang
    /en
        enums.php
    /it
        enums.php

```

All language files return an array of keyed strings. The array has 3 levels:

- first level key: the complete class name of the enum
- second level key: the name of the property to translate
- third level key: the name/value of the enum case.

The default property is `description` so if you use only that property you can use just a 2 level array.

```
// /lang/it/enums.php

return [
    // If you need to translate just the description property
    Status::class => [
        Status::PENDING() => 'In attesa', // using invokable trait functionality
        'ACCEPTED' => 'Accettato', // using the name of pure enum case
        'DISCARDED' => 'Rifiutato',
        'NO_RESPONSE' => 'Nessuna Risposta',
    ],
     // If you need to translate multiple properties (e.g. description, excerpt)
    StatusString::class => [
        'description' => [ // using invokable trait functionality
            StatusString::PENDING() => 'In attesa',
            StatusString::ACCEPTED() => 'Accettato',
            ...
        ],
        'excerpt' => [ // using the value of BackedEnum case
            "P" => 'In attesa',
            "A" => 'Accettato',
    ...
```

### Using Translation Strings As Keys

[](#using-translation-strings-as-keys)

Language strings are stored as JSON files in the lang directory (e.g. `lang/it.json`). In this example the `description` property is translated:

```
{
  "enums.Namespace\\StatusString.description.P": "In attesa",
  "...":"..."
}
```

But if you want to use this way, you can simply define the method on Enum class like this `description` method.

```
public function description(?string $lang = null): string
{
    return match ($this) {
        self::PENDING => __('Await decision', $lang),
        self::ACCEPTED => __('Recognized valid', $lang),
        self::DISCARDED => __('No longer useful', $lang),
        self::NO_RESPONSE => __('No response', $lang),
    };
```

`[property]()` method
---------------------

[](#property-method)

This dynamic method try to resolve `property()` method on the enum.
If the method not exist try to translate the instance value with the framework translation function `__("enums.Namespace\EnumClass.property.CASE_NAME")`.
Because the default property is `description`, if there isn't a translation to that property there is a fallback that takes the case name humanized. With the other properties, if the translation does not exist, the package throws a `TranslationMissing` exception.

static `[property]s()` method
-----------------------------

[](#static-propertys-method)

This dynamic method gets a list of case `property()` returns of the enum. The name of the method is the plural of the property so if you are using `property` it will be `properties()`.

```
StatusString::descriptions(); // ['Await decision','Recognized valid','No longer useful','No response']
StatusString::colors(); // ['#000000','#0000FF','#FF0000','#FFFFFF']
// Subset
StatusString::descriptions([StatusString::ACCEPTED, StatusString::NO_RESPONSE]); // ['Recognized valid','No response']
StatusString::colors([StatusString::ACCEPTED, StatusString::NO_RESPONSE]); // ['#0000FF','#FFFFFF']
// Forcing language
Status::descriptions(null, 'it'); // 🇮🇹 ['In attesa','Accettato','Rifiutato','Nessuna Risposta']
StatusString::colors(null, 'it'); // ['#000000','#0000FF','#FF0000','#FFFFFF']
// Subset and language
Status::descriptions([Status::NO_RESPONSE, Status::DISCARDED], 'it'); // 🇮🇹 ['Nessuna Risposta', 'Rifiutato']
StatusString::colors([StatusString::ACCEPTED, StatusString::NO_RESPONSE], 'it'); // ['#0000FF','#FFFFFF']
```

static `[property]sByName()` method
-----------------------------------

[](#static-propertysbyname-method)

This dynamic method returns an associative array of \[case name =&gt; `property()` result\]. The name of the method is the plural of the property so if you are using `property` it will be `propertiesByName()`.

```
StatusString::descriptionsByName(); // ['PENDING' => 'Await decision', 'ACCEPTED' => 'Recognized valid',...
StatusString::colorsByName(); // ['PENDING' => '#000000','ACCEPTED' => '#0000FF',...
Status::descriptionsByName(); // ['PENDING' => 'Await decision', 'ACCEPTED' => 'Recognized valid',...
// Subset
StatusString::descriptionsByName([StatusString::DISCARDED, StatusString::ACCEPTED]); // ['DISCARDED' => 'No longer useful', 'ACCEPTED' => 'Recognized valid']
Status::descriptionsByName([[Status::PENDING, Status::DISCARDED]); // ['PENDING' => 'Await decision', 'DISCARDED' => 'No longer useful']
// Forcing language
StatusString::descriptionsByName(null, 'it'); // 🇮🇹 ['P' => 'In attesa','A' => 'Accettato',...
// Subset and language
Status::descriptionsByName([Status::DISCARDED, Status::NO_RESPONSE], 'it'); // 🇮🇹 ['DISCARDED' => 'Rifiutato','NO_RESPONSE' => 'Nessuna Risposta',...
```

static `[property]sByValue()` method
------------------------------------

[](#static-propertysbyvalue-method)

This dynamic method returns an associative array of \[case value =&gt; `property()` result\] on `BackedEnum`, \[case name =&gt; `property()` result\] otherwise. The name of the method is the plural of the property so if you are using `property` it will be `propertiesByValue()`.

```
Status::descriptionsByValue(); // ['PENDING' => 'Await decision', 'ACCEPTED' => 'Recognized valid',...
StatusString::descriptionsByValue(); // ['P' => 'Await decision', 'A' => 'Recognized valid',...
StatusString::colorsByValue(); // ['P' => '#000000','A' => '#0000FF',...
// Subset
Status::descriptionsByValue([Status::PENDING, Status::DISCARDED]); // ['PENDING' => 'Await decision', 'DISCARDED' => 'No longer useful']
StatusString::descriptionsByValue([StatusString::DISCARDED, StatusString::ACCEPTED]); // ['D' => 'No longer useful', 'A' => 'Recognized valid']
StatusString::colorsByValue([[Status::PENDING, Status::DISCARDED]); // ['P' => '#000000', 'D' => '#FF0000']
// Forcing language
StatusString::descriptionsByValue(null, 'it'); // 🇮🇹 ['P' => 'In attesa','A' => 'Accettato',...
// Subset and language
Status::descriptionsByValue([StatusString::DISCARDED, StatusString::NO_RESPONSE], 'it'); // 🇮🇹 ['DISCARDED' => 'Rifiutato','NO_RESPONSE' => 'Nessuna Risposta',...
```

### Special Thanks

[](#special-thanks)

- Datomatic Team

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance68

Regular maintenance activity

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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 ~326 days

Total

3

Last Release

188d ago

Major Versions

1.0.0 → v2.0.02024-04-14

v2.0.0 → v3.0.02025-11-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/46e3a500894af089bd0454a7091114e0959fb7f300353aa30e1e3a6548be9d6b?d=identicon)[suleymanozev](/maintainers/suleymanozev)

---

Top Contributors

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

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/suleymanozev-laravel-enum-helper/health.svg)

```
[![Health](https://phpackages.com/badges/suleymanozev-laravel-enum-helper/health.svg)](https://phpackages.com/packages/suleymanozev-laravel-enum-helper)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[datomatic/laravel-enum-helper

Simple opinionated framework agnostic PHP 8.1 enum helper for Laravel

33219.6k6](/packages/datomatic-laravel-enum-helper)[anahkiasen/former

A powerful form builder

1.4k1.4M14](/packages/anahkiasen-former)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)

PHPackages © 2026

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