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.0.2(1y ago)32.4kMITPHPPHP ^8.1

Since Aug 10Pushed 11mo 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 1mo ago

READMEChangelog (2)Dependencies (6)Versions (4)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)

Overview
--------

[](#overview)

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

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

[](#installation)

To install the Laravel `Enumable` trait, add it to your project via Composer:

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

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

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.0 or higher

Usage
-----

[](#usage)

Include the `Enumable` trait in your enum classes:

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

enum YourEnum: string
{
    use Enumable;

    case Example = 'example';
    // Add your cases here
}
```

### Methods

[](#methods)

#### Class Methods

[](#class-methods)

- `values()`: Returns an array of all enum values.
- `names()`: Returns an array of all enum names.
- `labels()`: Converts the enum to an associative array with values as keys and labels as values.
- `getCase(string $value)`: Returns the enum case for the given value.
- `getName(string $value)`: Returns the name of the enum case for the given value.
- `getLabel(string $value)`: Returns the label of the enum case for the given value.
- `toArray()`: Converts the enum to an associative array with values as keys and names as values.
- `toCollection()`: Converts the enum to a Laravel collection.
- `toSelectArray()`: Alias for toLabelsArray().
- `exists(object|string $value)`: Checks if the given value exists in the enum.
- `random()`: Returns a random enum case.
- `default()`: Returns the default enum case.
- `first()`: Returns the first enum case.
- `last()`: Returns the last enum case.
- `count()`: Returns the number of enum cases.
- `only(array $cases)`: Returns a new object with only the specified cases.
- `except(array $cases)`: Returns a new object with all cases except the specified ones.
- `generate(array $cases)`: Generates a new object with the given cases.

#### Instance (Object) Methods

[](#instance-object-methods)

- `label()`: Returns the label of the enum case.
- `headline()`: Returns the headline of the enum case.
- `str(bool $label = false)`: Returns a new object to apply Laravel string helper methods.

### Examples

[](#examples)

```
// Class methods
YourEnum::values(); // ['example']
YourEnum::names(); // ['Example']
YourEnum::labels(); // ['example' => 'Example']
YourEnum::getCase('example'); // YourEnum::Example
YourEnum::getName('example'); // 'Example'
YourEnum::getLabel('example'); // 'Example'
YourEnum::toArray(); // ['example' => 'Example']
YourEnum::toCollection(); // Collection {#1 ▼
    #items: App\Enums\YourEnum [▼
        "name" => "Example",
        "value" => "example",
    ]
}
YourEnum::toSelectArray(); // ['example' => 'Example']
YourEnum::exists('example'); // true
YourEnum::random(); // YourEnum::Example
YourEnum::default(); // YourEnum::Example
YourEnum::first(); // YourEnum::Example
YourEnum::last(); // YourEnum::Example
YourEnum::count(); // 1
YourEnum::only(['Example']); // YourEnum::Example
YourEnum::except(['Example']); // YourEnum::Example
YourEnum::generate(['Example']); // YourEnum::Example

// Instance methods
YourEnum::Example->label(); // 'Example'
YourEnum::Example->headline(); // 'Example'
YourEnum::Example->str()->camel(); // 'example'
YourEnum::Example->str()->plural(); // 'Examples'
```

### Custom Labels

[](#custom-labels)

Override the `setLabels` method in your enum class to provide custom labels:

```
public static function setLabels(): array
{
    return [
        self::Example->value => 'Example Custom Label',
    ];
}
```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance46

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Total

3

Last Release

636d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/913cb3b2884c92ebbd8a351a895d527c4d5de57355dbe2dadfcb3640be029d7d?d=identicon)[dilovan](/maintainers/dilovan)

---

Top Contributors

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

---

Tags

laraveldilovanmatinienumable

###  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

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M626](/packages/spatie-laravel-data)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[marcelweidum/filament-expiration-notice

Customize the livewire expiration notice

9169.0k4](/packages/marcelweidum-filament-expiration-notice)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

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