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

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

vixen/laravel-enums
===================

A Laravel package that enhances PHP enums.

1.1.0(3mo ago)05↓91.7%MITPHPPHP ^8.3

Since Jan 13Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/vixen-tech/laravel-enums)[ Packagist](https://packagist.org/packages/vixen/laravel-enums)[ RSS](/packages/vixen-laravel-enums/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

Laravel Enums
=============

[](#laravel-enums)

A collection of composable traits and attributes for working with PHP backed enums in Laravel.

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

[](#requirements)

- PHP 8.3+
- Laravel 11, 12, or 13

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

[](#installation)

```
composer require vixen/laravel-enums
```

Usage
-----

[](#usage)

Add any combination of traits to your backed enum:

```
use Vixen\Enums\Attributes\Description;
use Vixen\Enums\Attributes\Label;
use Vixen\Enums\Attributes\LongLabel;
use Vixen\Enums\Attributes\ShortLabel;
use Vixen\Enums\HasDescriptions;
use Vixen\Enums\HasLabels;
use Vixen\Enums\HasOptions;
use Vixen\Enums\HasValues;
use Vixen\Enums\Filterable;
use Vixen\Enums\Snakeable;
use Vixen\Enums\ToArray;
use Vixen\Enums\ToValue;

enum Status: string
{
    use HasDescriptions;
    use HasLabels;
    use HasOptions;
    use HasValues;
    use Filterable;
    use Snakeable;
    use ToArray;
    use ToValue;

    #[Label('Pending')]
    #[LongLabel('Pending Review')]
    #[ShortLabel('PND')]
    #[Description('Items waiting to be reviewed by an administrator')]
    case Pending = 'pending';

    #[Label('Approved')]
    #[LongLabel('Approved Review')]
    #[ShortLabel('APR')]
    #[Description('Items that have passed review')]
    case Approved = 'approved';

    #[Label('Rejected'), LongLabel('Rejected Review'), ShortLabel('REJ')]
    case Rejected = 'rejected';
}
```

Traits
------

[](#traits)

### HasLabels

[](#haslabels)

Provides label functionality using `#[Label]`, `#[LongLabel]`, and `#[ShortLabel]` attributes.

```
// Static methods — return a Collection keyed by enum value
Status::labels();      // ['pending' => 'Pending', 'approved' => 'Approved', ...]
Status::longLabels();  // ['pending' => 'Pending Review', ...]
Status::shortLabels(); // ['pending' => 'PND', ...]

// Instance methods — return the label for a single case
Status::Pending->label();      // 'Pending'
Status::Pending->longLabel();  // 'Pending Review'
Status::Pending->shortLabel(); // 'PND'
```

When no attribute is provided, a label is auto-generated from the case name:

```
case Pending = 'pending';
// Pending->label() returns 'Pending'
```

#### Label type parameter

[](#label-type-parameter)

Instead of separate attributes, you can use the `type` parameter on `#[Label]`:

```
#[Label('Pending')]                        // default label
#[Label('Pending Review', type: 'long')]   // equivalent to #[LongLabel(...)]
#[Label('PND', type: 'short')]             // equivalent to #[ShortLabel(...)]
```

#### Fallback chain

[](#fallback-chain)

When requesting a specific label type (e.g., `longLabel()`), the resolution order is:

1. The exact attribute (`#[LongLabel]` or `#[Label(..., type: 'long')]`)
2. The default `#[Label]`
3. Auto-generated label from the case name

#### Translation support

[](#translation-support)

`#[Label]` and `#[LongLabel]` values are passed through Laravel's `__()` helper, so you can use translation keys:

```
#[Label('enums.status.pending')]
case Pending = 'pending';
```

`#[ShortLabel]` returns the raw string without translation, since it's intended for abbreviations.

### HasDescriptions

[](#hasdescriptions)

Provides description functionality using the `#[Description]` attribute. Useful for longer descriptive text alongside labels.

```
// Static method — returns a Collection keyed by enum value
Status::descriptions();
// ['pending' => 'Items waiting to be reviewed by an administrator', 'approved' => 'Items that have passed review', 'rejected' => null]

// Instance method — returns the description for a single case, or null
Status::Pending->description();     // 'Items waiting to be reviewed by an administrator'
Status::Rejected->description();    // null
```

Returns `null` when no `#[Description]` attribute is present on a case.

#### Translation support

[](#translation-support-1)

`#[Description]` values are passed through Laravel's `__()` helper, so you can use translation keys:

```
#[Description('enums.status.pending_description')]
case Pending = 'pending';
```

### HasOptions

[](#hasoptions)

Returns label-value pairs as a Collection, useful for select dropdowns and form components. Requires the enum to provide a `label()` method (typically via `HasLabels`) and a `description()` method (typically via `HasDescriptions`).

```
Status::options();
// [
//     ['label' => 'Pending', 'value' => 'pending'],
//     ['label' => 'Approved', 'value' => 'approved'],
//     ['label' => 'Rejected', 'value' => 'rejected'],
// ]

Status::descriptiveOptions();
// [
//     ['label' => 'Pending', 'value' => 'pending', 'description' => 'Items waiting to be reviewed by an administrator'],
//     ['label' => 'Approved', 'value' => 'approved', 'description' => 'Items that have passed review'],
//     ['label' => 'Rejected', 'value' => 'rejected', 'description' => null],
// ]
```

#### Customizing fields with `only`

[](#customizing-fields-with-only)

Both `options()` and `descriptiveOptions()` accept an optional `only` parameter to customize which fields appear in the returned arrays. The `value` field is always included.

```
Status::options(only: ['shortLabel', 'description']);
// [
//     ['value' => 'pending', 'shortLabel' => 'PND', 'description' => 'Items waiting to be reviewed by an administrator'],
//     ['value' => 'approved', 'shortLabel' => 'APR', 'description' => 'Items that have passed review'],
//     ['value' => 'rejected', 'shortLabel' => 'REJ', 'description' => null],
// ]

// Use ['*'] to include all available fields
Status::options(only: ['*']);
// [
//     ['value' => 'pending', 'name' => 'Pending', 'label' => 'Pending', 'shortLabel' => 'PND', 'longLabel' => 'Pending Review', 'description' => '...'],
//     ...
// ]
```

Available fields: `value`, `name`, `label`, `shortLabel`, `longLabel`, `description`. An `InvalidArgumentException` is thrown for fields that don't exist on the enum.

### HasValues

[](#hasvalues)

Returns a Collection of all backed values.

```
Status::values(); // ['pending', 'approved', 'rejected']
```

### Filterable

[](#filterable)

Select or exclude specific cases by name. Returns an `EnumCollection` (see below), so you can chain `toOptions()` or `toDescriptiveOptions()` directly.

```
Status::only(['Pending', 'Approved']);
// EnumCollection of [Status::Pending, Status::Approved]

Status::except(['Rejected']);
// EnumCollection of [Status::Pending, Status::Approved]

// Chain with EnumCollection methods
Status::only(['Pending', 'Approved'])->toOptions();
// [
//     ['label' => 'Pending', 'value' => 'pending'],
//     ['label' => 'Approved', 'value' => 'approved'],
// ]
```

### EnumCollection

[](#enumcollection)

A custom collection class extending Laravel's `Collection`, designed to hold enum cases and provide convenient conversion methods.

```
use Vixen\Enums\EnumCollection;

$collection = new EnumCollection(Status::cases());

$collection->toOptions();
// [
//     ['label' => 'Pending', 'value' => 'pending'],
//     ['label' => 'Approved', 'value' => 'approved'],
//     ['label' => 'Rejected', 'value' => 'rejected'],
// ]

$collection->toDescriptiveOptions();
// [
//     ['label' => 'Pending', 'value' => 'pending', 'description' => 'Items waiting to be reviewed by an administrator'],
//     ['label' => 'Approved', 'value' => 'approved', 'description' => 'Items that have passed review'],
//     ['label' => 'Rejected', 'value' => 'rejected', 'description' => null],
// ]

// Customize fields with the only parameter
$collection->toOptions(only: ['shortLabel', 'description']);
// [
//     ['value' => 'pending', 'shortLabel' => 'PND', 'description' => '...'],
//     ...
// ]
```

`toOptions()` requires the enum to use `HasLabels`. `toDescriptiveOptions()` additionally requires `HasDescriptions`. Both methods accept an optional `only` parameter — see [HasOptions](#hasoptions) for details.

Returned automatically by `Filterable::only()` and `Filterable::except()`.

### Snakeable

[](#snakeable)

Converts the case name to snake\_case.

```
Status::Pending->snake();       // 'pending'
Status::PendingReview->snake(); // 'pending_review'
```

### ToArray

[](#toarray)

Converts a single case to an associative array. Requires the enum to provide a `label()` method.

```
Status::Pending->toArray();
// ['label' => 'Pending', 'value' => 'pending']
```

### ToValue

[](#tovalue)

Explicit accessor for the backed value.

```
Status::Pending->toValue(); // 'pending'
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

Credits
-------

[](#credits)

- [Alex Torscho](https://alextorscho.com)
- All Contributors

License
-------

[](#license)

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

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance82

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Total

4

Last Release

91d ago

PHP version history (2 changes)1.0PHP ^8.2

1.1.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/05ca9e5f22ddfbacac280fe76010f41a245cce7916d37ba5ad5d6b873ad63f29?d=identicon)[atorscho](/maintainers/atorscho)

---

Top Contributors

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

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[illuminate/pipeline

The Illuminate Pipeline package.

9348.3M267](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10533.5M991](/packages/illuminate-pagination)[illuminate/redis

The Illuminate Redis package.

8314.4M363](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

224.5M132](/packages/illuminate-cookie)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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