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

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

kwaadpepper/enum
================

Enums to use for any project

3.0.0(2y ago)24.3k1MITPHPPHP &gt;=8.2

Since Mar 1Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Kwaadpepper/enum)[ Packagist](https://packagist.org/packages/kwaadpepper/enum)[ Docs](https://github.com/kwaadpepper/enum)[ RSS](/packages/kwaadpepper-enum/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (15)Used By (1)

Enum
====

[](#enum)

[![GitHub](https://camo.githubusercontent.com/387fcf05f42c42805ae799d453d138b70314841a2cde5658bc046e889d8b2d3c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4b776161647065707065722f656e756d3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/387fcf05f42c42805ae799d453d138b70314841a2cde5658bc046e889d8b2d3c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4b776161647065707065722f656e756d3f7374796c653d666c61742d737175617265)[![Latest Version on Packagist](https://camo.githubusercontent.com/05cdc77d5cba93ba003c5bcfcef07bede2508a107007f824d745cbdbb7e0aba8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b776161647065707065722f656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kwaadpepper/enum)[![Total Downloads](https://camo.githubusercontent.com/4eeabecd2ad1692d26e16cfcf931420f2a1c4d3ebc75dc61cc7b7939785ce283/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b776161647065707065722f656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kwaadpepper/enum)[![GitHub Workflow Status](https://camo.githubusercontent.com/0e175dadbc53c12bfe64f6ebf643f6dbb9bf9fe0f4026a35e20e53e28dfc1f9a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4b776161647065707065722f656e756d2f7068702e796d6c3f6272616e63683d6d61737465723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/0e175dadbc53c12bfe64f6ebf643f6dbb9bf9fe0f4026a35e20e53e28dfc1f9a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4b776161647065707065722f656e756d2f7068702e796d6c3f6272616e63683d6d61737465723f7374796c653d666c61742d737175617265)

This package goal is to provide a complete solution to lack a long time php weakness : it do not have any `enum` support. This will change with [**php 8 enums proposition**](https://php.watch/versions/8.1/enums). In the mean time we still a support for this allowing us to generate generic and extendable applications (instead of have singletons sql tables..).

You will be able to use enums in any project using a simple definition, take a look at example [Basic](examples/BasicEnum.php) or a [more sophisticated Example](examples/Days.php)

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

[](#installation)

Via Composer

```
$ composer require kwaadpepper/enum
```

---

Usage
-----

[](#usage)

**All enum have two properties : `label` and `value`, only value has to be unique. Each enum can have multiple options all written on class comment as static methods, these have to be unique !**

- On Any project, take a look on [examples](examples) to create an enum class.

1. **Invoke an enum value**

    ```
    Days::mon()
    ```
2. **Compare enums**

    ```
    Days::mon()->equals(Days::tue()) // false
    Days::mon()->equals(Days::mon()) // true
    Days::mon()->value === Days::tue()->value // false
    Days::mon()->value === Days::mon()->value // true
    ```
3. **Print an enum**

    ```
    echo Days::mon(); // 2
    echo Days::tue(); // 4
    echo Days::mon()->label; // Monday
    ```

    As you can see enum implements the \_\_toString method which you can override to display the label instead of the value. This default behavior is set like this for a better behavior in laravel.
4. **Serialise an enum**

    ```
    echo json_encode(Days::mon()); // {"label":"Monday","value":2}
    ```

    Enums implement the JsonSerializable interface

- On a Laravel project you can use enums in multiple ways

1. **As a property**

    ```
    // Add theses to your model
     use CastsEnums;
     protected $enumCasts = [
         'day' => Days::class
     ];
    ```

    This will allow you model to store an enum in database using its value, and then cast the property to an enum when accessing it
2. **As a route parameter**

    Define a route like the following

    ```
    Route::get('/days/{day}', function (Days $day) {
             return response()->json([$day]);
         })->middleware('bindings');
     // OR
     Route::get('/days/{day}', [DayController::class, 'getDay']);
    ```

    Then on your controller for the `DayController` example

    ```
    public function getDay(Request $request, Day $day) {
        return response()->json([$day]);
    }
    ```
3. **As a request parameter using validation**

    Take a look at [this request example](tests/Requests/PassDayRequest.php).

    ```
    new EnumIsValidRule(Days::class)
    ```

    It use EnumIsValidRule to validate the parameter as being a valid enum value.

    **Note that you may still have to cast your parameter to int if your enum value is an int, as enum check is strict**
4. **As a model primary Key**

    Take a look at [unit test](tests/BaseEnumRoutableTest.php) using [the Report enum class from tests](tests/Models/Report.php)

---

Change log
----------

[](#change-log)

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

---

Testing
-------

[](#testing)

```
$ composer test
```

---

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

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todolist.

---

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

---

Credits
-------

[](#credits)

- [Jérémy Munsch](https://github.com/kwaadpepper)
- [All Contributors](../../contributors)

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity73

Established project with proven stability

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

Recently: every ~156 days

Total

14

Last Release

1081d ago

Major Versions

0.1.3 → 2.0.02021-08-13

2.1.3 → 3.0.02023-06-02

PHP version history (3 changes)2.1.0PHP ^7.3

2.1.3PHP &gt;=7.3

3.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/7d6fe69e010efceae2bd9a92eb6463139fff339c94c545b6b7b1210a00d963e4?d=identicon)[Kwaadpepper](/maintainers/Kwaadpepper)

---

Top Contributors

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

---

Tags

enumenumslaravellaravel-packagestand-alonelaravelenum

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[simplesquid/nova-enum-field

A Laravel Nova field to add enums to resources.

52391.9k2](/packages/simplesquid-nova-enum-field)[nasyrov/laravel-enums

Laravel package for Enum implementation.

3272.5k](/packages/nasyrov-laravel-enums)[lazerg/laravel-enum-pro

A powerful PHP enum extension with collection support, random selection, and magic static calls

4319.0k](/packages/lazerg-laravel-enum-pro)[mindtwo/native-enum

Package for using native php enums.

2626.0k1](/packages/mindtwo-native-enum)[artisaninweb/laravel-enum

A provider for Enums in Laravel.

1187.5k](/packages/artisaninweb-laravel-enum)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)

PHPackages © 2026

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