PHPackages                             sezer/enum-helpers - 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. sezer/enum-helpers

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

sezer/enum-helpers
==================

Elegant and extensible helper library for PHP enums: filter, validate, and extend your enums with ease.

v1.1.0(10mo ago)03MITPHPPHP ^8.1

Since Jul 17Pushed 10mo agoCompare

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

READMEChangelogDependencies (1)Versions (3)Used By (0)

🧰 sezer/enum-helpers
====================

[](#-sezerenum-helpers)

> Elegant and lightweight helpers for PHP enums. Adds only(), except(), onlyList(), exceptList(), automatic validation, and custom exceptions — to make working with PHP 8.1+ enums clean and easy.

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

[](#installation)

description: Install this package via Composer:

```
composer require sezer/enum-helpers

```

Usage:
======

[](#usage)

Add the `EnumTrait` to your enum and use the methods:

```
use Sezer\EnumHelpers\Traits\EnumTrait;

enum OrderStatus: string {
    use EnumTrait;

  case PENDING  = 'pending';
  case APPROVED = 'approved';
  case REJECTED = 'rejected';
  case COMPLETE = 'complete';
  case RETURNED = 'returned';
}
```

Examples:
=========

[](#examples)

- Filter with `only()`Keep only specified cases.

```
  $result = OrderStatus::only(['PENDING', 'APPROVED']);
  print_r($result);
  output:
      [
      'PENDING'  => OrderStatus::PENDING,
      'APPROVED' => OrderStatus::APPROVED
      ]
```

- Exclude with `except()`Exclude specified cases.

```
  $result = OrderStatus::except(['REJECTED']);
  print_r($result);
  output:
  [
  'PENDING'  => OrderStatus::PENDING,
  'APPROVED' => OrderStatus::APPROVED
  ]
```

- 📜 Get just the values as plain array `onlyList();`

```
  OrderStatusEnum::onlyList(['PENDING', 'APPROVED']);

    output: ['pending', 'approved']
```

- `exceptList()`

```
OrderStatusEnum::exceptList(['COMPLETE']);
output: ['pending', 'approved', 'rejected', 'returned']
```

🎯 With Laravel
==============

[](#-with-laravel)

> ### ✨ If your model has Enum cast:
>
> [](#-if-your-model-has-enum-cast)

```
protected $casts = [
    'order_status' => OrderStatusEnum::class,
];
```

*You can pass Enum cases directly in queries:*

```
Order::whereIn(
    'order_status',
    OrderStatusEnum::except(['COMPLETE'])
)->get();
```

```

@foreach (OrderStatusEnum::except(['COMPLETE']) as $key => $status)
    {{ ucfirst(strtolower($key)) }}
@endforeach

```

*In Validation:*

```
use Illuminate\Validation\Rule;

$request->validate([
    'status' => [
        'required',
        Rule::in(OrderStatusEnum::exceptList(['COMPLETE']))
    ]
]);
```

✨ If your model does NOT have Enum cast:
========================================

[](#-if-your-model-does-not-have-enum-cast)

> You need the -&gt;value of each case:

```
Order::whereIn(
    'order_status',
    OrderStatusEnum::exceptList(['COMPLETE'])
)->get();
```

*In Blade:*

```

@foreach (OrderStatusEnum::exceptList(['COMPLETE']) as $status)
    {{ ucfirst($status) }}
@endforeach

```

*In Validation:*

```
$request->validate([
    'status' => [
        'required',
        Rule::in(OrderStatusEnum::exceptList(['COMPLETE']))
    ]
]);
```

Errors:
=======

[](#errors)

Invalid keys

> If you pass an invalid case name to `only()` or `except()`, an `InvalidEnumKeyException` is thrown. example: OrderStatus::only(\['INVALID'\]); Sezer\\EnumHelpers\\Exceptions\\InvalidEnumKeyException: Invalid enum key: INVALID

Test
----

[](#test)

```
 vendor/bin/phpunit

```

Authors
-------

[](#authors)

[@sezer](https://github.com/hussiensezer)

🔗 Links
-------

[](#-links)

[![linkedin](https://camo.githubusercontent.com/9745a59ad4a919d2e524512c3f732c820d4aa0fe927def4f37c4aba08f7e42bc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c696e6b6564696e2d3041363643323f7374796c653d666f722d7468652d6261646765266c6f676f3d6c696e6b6564696e266c6f676f436f6c6f723d7768697465)](https://www.linkedin.com/in/hussien-attia/)

Support
-------

[](#support)

For support, email

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance54

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

2

Last Release

305d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe0bbfee223fbc8ffcf74a1b5a1ff33f3a418762f4222aa40143c27860dd16a2?d=identicon)[hussiensezer](/maintainers/hussiensezer)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sezer-enum-helpers/health.svg)

```
[![Health](https://phpackages.com/badges/sezer-enum-helpers/health.svg)](https://phpackages.com/packages/sezer-enum-helpers)
```

###  Alternatives

[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)

PHPackages © 2026

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