PHPackages                             laravel-enso/enums - 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. laravel-enso/enums

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

laravel-enso/enums
==================

Enums for Laravel Enso

3.0.4(2mo ago)055.4k—1.6%320MITPHPPHP ^8.0CI failing

Since Aug 27Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/laravel-enso/enums)[ Packagist](https://packagist.org/packages/laravel-enso/enums)[ Docs](https://github.com/laravel-enso/enums)[ RSS](/packages/laravel-enso-enums/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (4)Versions (42)Used By (20)

Enums
=====

[](#enums)

[![License](https://camo.githubusercontent.com/d0012532f050e3aa8c3e1b1c64896186873ff9176ae70e9b9102258c5fc98f6a/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f656e756d732f6c6963656e7365)](LICENSE)[![Stable](https://camo.githubusercontent.com/066e30fe2c6ef2ec9f860d6e00d839a861f8c3978ab79f26ded27b04355404a6/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f656e756d732f76657273696f6e)](https://packagist.org/packages/laravel-enso/enums)[![Downloads](https://camo.githubusercontent.com/b6583cc8fa627e9d912f9f9092e5e0dbed838e50683b36725ea44710fa401495/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f656e756d732f646f776e6c6f616473)](https://packagist.org/packages/laravel-enso/enums)[![PHP](https://camo.githubusercontent.com/ef6afd4ccdaa708a9b1a0a353d6d03a13ca1f03887b8db701d4118dc30a6735a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e302532422d3737376262342e737667)](composer.json)[![Issues](https://camo.githubusercontent.com/d48fea14875a6ea1a0c1689134b2192d98cac2d8a64918750d88182e0fd0106b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6c61726176656c2d656e736f2f656e756d732e737667)](https://github.com/laravel-enso/enums/issues)[![Merge Requests](https://camo.githubusercontent.com/cd956058a8dc952299f9302faefc1f6934d3283aec0a8e30bb7c9ac20c737064/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6c61726176656c2d656e736f2f656e756d732e737667)](https://github.com/laravel-enso/enums/pulls)

Description
-----------

[](#description)

Enums provides both legacy class-based enumerations and frontend-ready native PHP enum discovery for Laravel Enso.

The package keeps backwards compatibility with Enso's original enum classes while also scanning vendor and application `Enums` folders for native PHP enums that implement specific contracts. Those enums can then be registered into application state and exposed to the frontend in a normalized shape.

It is used throughout the Enso ecosystem for typed option lists, shared UI state, and enum mapping between backend code and frontend consumers.

::: warning Note Since PHP now provides native enums, we strongly recommend migrating new and existing code to native PHP enums wherever possible.

We still intend to keep supporting the Enso enum registry layer for ecosystem integration and frontend state registration, even as the legacy custom enum implementation is phased out. :::

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

[](#installation)

Install the package:

```
composer require laravel-enso/enums
```

The package auto-registers:

- `LaravelEnso\Enums\AppServiceProvider`
- `LaravelEnso\Enums\EnumServiceProvider`

If you want to customize which vendor namespaces are scanned, publish the configuration:

```
php artisan vendor:publish --tag=enums-config
```

If you want an application provider for registering legacy enums explicitly, publish the stub:

```
php artisan vendor:publish --tag=enum-provider
```

Default configuration:

```
return [
    'vendors' => ['laravel-enso'],
];
```

For native frontend enums, place enum classes under your PSR-4 `Enums` folder. In a standard Laravel application this means `app/Enums`.

Features
--------

[](#features)

- Provides a base class for legacy class-based enums.
- Supports native PHP enums for frontend/state registration.
- Scans configured vendor packages and the host application for enum classes.
- Registers enum state under a single `enums` store payload.
- Exposes a facade for registering and removing legacy enums.
- Supports optional enum mapping through a dedicated `Mappable` contract.
- Includes helper traits for select lists, searching, and random case selection.

Usage
-----

[](#usage)

### Legacy Class-Based Enums

[](#legacy-class-based-enums)

Extend `LaravelEnso\Enums\Services\Enum`:

```
use LaravelEnso\Enums\Services\Enum;

class Roles extends Enum
{
    public const Admin = 1;
    public const Supervisor = 2;
    public const User = 3;
}
```

Available helpers:

```
Roles::get(1);
Roles::has(2);
Roles::keys();
Roles::values();
Roles::select();
Roles::json();
```

### Native PHP Enums For Frontend State

[](#native-php-enums-for-frontend-state)

Implement `LaravelEnso\Enums\Contracts\Frontend` on a backed enum:

```
use LaravelEnso\Enums\Contracts\Frontend;
use LaravelEnso\Enums\Contracts\Mappable;
use LaravelEnso\Enums\Traits\Select;

enum Status: int implements Frontend, Mappable
{
    use Select;

    case Draft = 0;
    case Published = 1;

    public static function registerBy(): string
    {
        return 'statuses';
    }

    public function map(): mixed
    {
        return match ($this) {
            self::Draft => 'Draft',
            self::Published => 'Published',
        };
    }
}
```

The enum will be discovered from an `Enums` folder and registered under the key returned by `registerBy()`.

### Legacy Enum Registration

[](#legacy-enum-registration)

Register legacy enums through the facade or `EnumServiceProvider`:

```
use LaravelEnso\Enums\Facades\Enums;

Enums::register([
    'roles' => \App\Enums\Roles::class,
]);
```

API
---

[](#api)

### Configuration

[](#configuration)

`config/enums.php`

Keys:

- `vendors`

The scanner checks:

- `vendor//*`
- the application base path and its PSR-4 root

### Service Providers

[](#service-providers)

- `LaravelEnso\Enums\AppServiceProvider`
- `LaravelEnso\Enums\EnumServiceProvider`

Responsibilities:

- merge and publish config
- publish the legacy enum provider stub
- register legacy enums listed in the provider's `$register` property

### Legacy Enum Base Class

[](#legacy-enum-base-class)

`LaravelEnso\Enums\Services\Enum`

Key methods:

- `constants(): array`
- `get($key)`
- `has($key): bool`
- `keys()`
- `values()`
- `json(): string`
- `array(): array`
- `all(): array`
- `object(): object`
- `collection()`
- `select()`
- `localisation(bool $state = true): void`

### Native Enum Discovery

[](#native-enum-discovery)

- `LaravelEnso\Enums\Services\Source`
- `LaravelEnso\Enums\Services\Enums`

Requirements for discovery:

- enum must exist in an `Enums` folder
- enum must implement `LaravelEnso\Enums\Contracts\Frontend`

Optional mapping:

- implement `LaravelEnso\Enums\Contracts\Mappable`

### Legacy Enum Registry

[](#legacy-enum-registry)

- `LaravelEnso\Enums\Services\LegacyEnums`
- `LaravelEnso\Enums\Facades\Enums`

Key methods:

- `register($enums)`
- `remove($aliases)`
- `all(): array`

### State Provider

[](#state-provider)

`LaravelEnso\Enums\State\Enums`

Provides merged enum state for frontend consumption under the `enums` store key.

### Traits

[](#traits)

- `LaravelEnso\Enums\Traits\Select`
- `LaravelEnso\Enums\Traits\Search`
- `LaravelEnso\Enums\Traits\Random`

Depends On
----------

[](#depends-on)

Required Enso packages:

- [`laravel-enso/core`](https://docs.laravel-enso.com/backend/core.html) [↗](https://github.com/laravel-enso/core)
- [`laravel-enso/helpers`](https://docs.laravel-enso.com/backend/helpers.html) [↗](https://github.com/laravel-enso/helpers)

Framework dependency:

- [`laravel/framework`](https://github.com/laravel/framework) [↗](https://github.com/laravel/framework)

Companion frontend package:

- [`@enso-ui/enums`](https://docs.laravel-enso.com/frontend/enums.html) [↗](https://github.com/enso-ui/enums)

Contributions
-------------

[](#contributions)

are welcome. Pull requests are great, but issues are good too.

Thank you to all the people who already contributed to Enso!

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity30

Limited adoption so far

Community34

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~71 days

Recently: every ~4 days

Total

35

Last Release

67d ago

Major Versions

1.2.2 → 2.0.02020-06-23

2.7.0 → 3.0.02026-04-09

PHP version history (4 changes)1.0.0PHP &gt;=7.1.0

1.1.4PHP &gt;=7.3.0

1.2.0PHP &gt;=7.4.0

2.3.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16073274?v=4)[Adrian Ocneanu](/maintainers/aocneanu)[@aocneanu](https://github.com/aocneanu)

---

Top Contributors

[![aocneanu](https://avatars.githubusercontent.com/u/16073274?v=4)](https://github.com/aocneanu "aocneanu (38 commits)")[![gandesc](https://avatars.githubusercontent.com/u/14071925?v=4)](https://github.com/gandesc "gandesc (13 commits)")[![vmcvlad](https://avatars.githubusercontent.com/u/37445394?v=4)](https://github.com/vmcvlad "vmcvlad (11 commits)")[![raftx24](https://avatars.githubusercontent.com/u/10864136?v=4)](https://github.com/raftx24 "raftx24 (5 commits)")[![AbdullahiAbdulkabir](https://avatars.githubusercontent.com/u/33360580?v=4)](https://github.com/AbdullahiAbdulkabir "AbdullahiAbdulkabir (4 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (3 commits)")[![GITmanuela](https://avatars.githubusercontent.com/u/44998004?v=4)](https://github.com/GITmanuela "GITmanuela (2 commits)")

---

Tags

enumenumerationlaravellaravel-ensopackagestructureenumslaravel-enso

### Embed Badge

![Health badge](/badges/laravel-enso-enums/health.svg)

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

###  Alternatives

[laravel-enso/tables

Server-side data tables and export backend for Laravel Enso

63355.1k83](/packages/laravel-enso-tables)[laravel-enso/localisation

Language and translation management for Laravel Enso

1362.8k10](/packages/laravel-enso-localisation)[laravel-enso/data-import

Excel Importer dependency for Laravel Enso

2044.0k6](/packages/laravel-enso-data-import)[laravel-enso/forms

JSON-based form builder for Laravel Enso

12354.2k84](/packages/laravel-enso-forms)[laravel-enso/tutorials

Tutorial management backend for Laravel Enso

1140.7k](/packages/laravel-enso-tutorials)[laravel-enso/comments

Comments Manager for Laravel Enso

1140.8k1](/packages/laravel-enso-comments)

PHPackages © 2026

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