PHPackages                             dilovanmatini/laravel-enumable - 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. dilovanmatini/laravel-enumable

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

dilovanmatini/laravel-enumable
==============================

The Laravel Enumable trait provides a set of utility methods to enhance PHP enums. It includes methods for manipulating enum cases, retrieving labels, and converting enums to various formats.

v1.1.0(1mo ago)43.0kMITPHPPHP ^8.1CI passing

Since Aug 10Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/dilovanmatini/laravel-enumable)[ Packagist](https://packagist.org/packages/dilovanmatini/laravel-enumable)[ Docs](https://github.com/dilovanmatini/laravel-enumable)[ RSS](/packages/dilovanmatini-laravel-enumable/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (14)Versions (6)Used By (0)

Enumable Trait for Laravel
==========================

[](#enumable-trait-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5a55381f0a021937603d92ae8ee6e5d6acd536207f003529e2f06389e8a73ed6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64696c6f76616e6d6174696e692f6c61726176656c2d656e756d61626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dilovanmatini/laravel-enumable)[![Total Downloads](https://camo.githubusercontent.com/cead916687232c102e60aed202eddc1dfeb7f96fc07e75ba6f8937962e4e8e7a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64696c6f76616e6d6174696e692f6c61726176656c2d656e756d61626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dilovanmatini/laravel-enumable)[![License](https://camo.githubusercontent.com/c45da89094506a4b523ffd7a4999e0ddbf2f658f7b79e05c2422a1cb141c8d29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f64696c6f76616e6d6174696e692f6c61726176656c2d656e756d61626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dilovanmatini/laravel-enumable)

Native PHP enums with Laravel-friendly helpers for labels, selects, validation, and case filtering.

Overview
--------

[](#overview)

The `Enumable` trait enhances **backed** PHP enums (`string` or `int`) with utilities for forms, APIs, and validation—without replacing native enums.

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

[](#installation)

```
composer require dilovanmatini/laravel-enumable
```

No service provider or configuration is required.

Upgrading from 1.0.x? See [UPGRADE.md](UPGRADE.md).

Requirements
------------

[](#requirements)

- PHP 8.1 or higher (Laravel 13 applications require PHP 8.3+)
- Laravel 10, 11, 12, or 13

Usage
-----

[](#usage)

```
use DilovanMatini\Enumable\Traits\Enumable;

enum Status: string
{
    use Enumable;

    case Draft = 'draft';
    case Published = 'published';
}
```

Methods
-------

[](#methods)

### Class methods

[](#class-methods)

MethodDescription`values()`All backed values`names()`All case names`labels()``[value => label]``toSelectArray()`Alias of `labels()``toSelectArrayByName()``[name => label]``toArray()``[value => name]``toCollection()`Laravel collection of cases`getCase($value)`Resolve by value (`tryFrom` for backed enums)`tryFromValue($value)`Alias of `getCase()``fromName($name)`Resolve by case name`fromNameOrDefault($name)`Resolve by name or fall back to `default()``getName($value)`Case name for a value`getLabel($value)`Label for a value`exists($value)`Whether value, name, or case exists`random()`Random case`default()`Default case (override in your enum)`first()` / `last()`First or last case`count()`Number of cases`only($cases)`Filtered subset (full Enumable API)`except($cases)`Inverse filtered subset`generate($cases)`Build a filtered subset`rule()`Laravel `Rule::enum()``ruleOnly($cases)``Rule::in()` for a subset`ruleExcept($cases)``Rule::in()` excluding cases### Instance methods

[](#instance-methods)

MethodDescription`label()`Human-readable label`headline()`Headline from case name`trans($key, $replace, $locale)`Translation helper`is($other)`Compare to case, value, or name`isAny($others)`True if any match`in($others)`Alias of `isAny()``str($label = false)`String helpers (`camel`, `slug`, etc.)Examples
--------

[](#examples)

```
// Lists & selects
Status::values();           // ['draft', 'published']
Status::labels();           // ['draft' => 'Draft', 'published' => 'Published']
Status::toSelectArray();    // same as labels()

// Resolution
Status::getCase('draft');   // Status::Draft
Status::fromName('Draft');  // Status::Draft

// Validation (Form Request)
Status::rule();
Status::ruleOnly(['draft', 'published']);

// Filtering (subset supports static and instance calls, same as 1.0.x)
Status::except(['draft'])::labels();
Status::only([Status::Published])->cases();

// Instance helpers
Status::Draft->label();
Status::Draft->str()->slug();       // "draft"
Status::Draft->is('draft');         // true
```

### Custom labels

[](#custom-labels)

Prefer `labelsMap()` (or keep using `setLabels()` for backward compatibility):

```
public static function labelsMap(): array
{
    return [
        self::Draft->value => 'Draft (hidden)',
        self::Published->value => 'Live',
    ];
}
```

### Default case

[](#default-case)

Override `default()` on your enum:

```
public static function default(): self
{
    return self::Draft;
}
```

### Blade select

[](#blade-select)

```

    @foreach (Status::toSelectArray() as $value => $label)
        {{ $label }}
    @endforeach

```

### Eloquent

[](#eloquent)

Use Laravel's native enum casting:

```
protected $casts = [
    'status' => Status::class,
];
```

Backed enums only
-----------------

[](#backed-enums-only)

Methods that rely on a backed `value` (`values()`, `labels()`, `only()`, etc.) require `string` or `int` backed enums. Unit enums support name-based helpers such as `fromName()` and `exists()` by name.

Migrating from BenSampo/laravel-enum
------------------------------------

[](#migrating-from-bensampolaravel-enum)

BenSampoEnumable`getValue()``$case->value``getDescription()``$case->label()``toSelectArray()``toSelectArray()` or `labels()``coerce()``tryFromValue()` or `getCase()`Comparison with Other Enum Packages
-----------------------------------

[](#comparison-with-other-enum-packages)

Feature / PackageLaravel Enumable (this package)BenSampo\\EnumNative PHP Enums**Laravel Version Support**9.x, 10.x, 11.x, 12.x, 13.x (with `illuminate/*` deps)8.x, 9.x, 10.x, 11.xLaravel 9+ (for PHP 8.1+ enums)**Enum Backing**Native PHP 8.1+ enumsClass-based emulation pre-8.1, native post-8.1Native**Get All Cases/Values/Names**✔️ cases(), names(), values()✔️ getValues(), getNames(), getInstances()✔️ cases()**Labeling/Custom Labels**✔️ labels(), setLabels(), labelsMap() (+translate)✔️ description, custom labels via methodManual implementation**Array/Map Conversion**✔️ toArray(), toSelectArray(), toSelectArrayByName()✔️ asArray(), asSelectArray()Manual (array\_map/cases)**Validation Rules**✔️ rule(), ruleOnly(), ruleExcept(), integrate w/Validator✔️ validationRule()Manual**Lookup Helpers**✔️ tryFromValue(), fromName(), fromNameOrDefault()✔️ coerce(), fromKey(), fromValue(), etc.Native tryFrom()/from() (limited)**Comparison &amp; In Checks**✔️ is(), isAny(), in()✔️ isOneOf()Manual or custom**String Helpers**✔️ str(), slug(), snake(), camel(), etc. via EnumStringable❌❌**Translation Support**✔️ trans(), translation key helpers❌Manual**Subset/Filtering**✔️ only(), except(), generate()✔️ filter()Manual**Macroable/Extendability**❌ (not macroable, but adds helpers)✔️ Macroable (extend enum classes)Manual**Test/Type Coverage**✔️ (PHPStan level 8, extensive tests)GoodN/A**Zero Config (out-of-the-box)**✔️❌ (service provider if using Laravel integration)✔️ (once enum is defined)**Extra Features**EnumStringable (String inflection), advanced labelsEnum annotations, custom casting, traitsN/A**Legend**: ✔️ = Supported; ❌ = Not Supported; Manual = Can be achieved but requires additional code.
*Last reviewed: Laravel Enumable v1.1.0, BenSampo\\Enum v5.x, PHP 8.1+ enums.*

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for release notes.

License
-------

[](#license)

MIT © [Dilovan Matini](https://github.com/dilovanmatini)

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance91

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Total

5

Last Release

41d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3215461?v=4)[Dlovan Bashir Ali](/maintainers/dilovan)[@dilovan](https://github.com/dilovan)

---

Top Contributors

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

---

Tags

laravelenumphp-enumdilovanmatinienumable

###  Code Quality

TestsPest

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/dilovanmatini-laravel-enumable/health.svg)

```
[![Health](https://phpackages.com/badges/dilovanmatini-laravel-enumable/health.svg)](https://phpackages.com/packages/dilovanmatini-laravel-enumable)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k54.9M11.7k](/packages/illuminate-database)[illuminate/events

The Illuminate Events package.

13557.0M2.1k](/packages/illuminate-events)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/session

The Illuminate Session package.

9939.3M849](/packages/illuminate-session)[illuminate/broadcasting

The Illuminate Broadcasting package.

7127.2M209](/packages/illuminate-broadcasting)[illuminate/redis

The Illuminate Redis package.

8314.6M376](/packages/illuminate-redis)

PHPackages © 2026

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