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

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

nasyrov/laravel-enums
=====================

Laravel package for Enum implementation.

v1.1.11(5y ago)3273.6k↓67.2%9MITPHPPHP &gt;=7.0

Since Jun 12Pushed 5y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (14)Used By (0)

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

[](#laravel-enums)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6ccea32e76c23d8e4e10d252ff98d25b9352f5256e590f734cfddd33af27e8e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e617379726f762f6c61726176656c2d656e756d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nasyrov/laravel-enums)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/b0c52f6660f2fe63c573ceb8fc9d3790a204ccb795f48531595d608f6887ce9d/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6e617379726f762f6c61726176656c2d656e756d732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/nasyrov/laravel-enums)[![Coverage Status](https://camo.githubusercontent.com/0d459e84fa735038fc3326022522b6676795f2d9be8dd257f1944296824de2b1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6e617379726f762f6c61726176656c2d656e756d732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/nasyrov/laravel-enums/code-structure)[![Quality Score](https://camo.githubusercontent.com/970b67ca307ff7acbc6688bea9f52aa84d9d9132c97b3dcba8be57ce03c6b2ee/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6e617379726f762f6c61726176656c2d656e756d732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/nasyrov/laravel-enums)[![Total Downloads](https://camo.githubusercontent.com/09e6a37cfad023c5e70bd79691ccc80e305fffcfd25312db82b03aaba805f66d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e617379726f762f6c61726176656c2d656e756d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nasyrov/laravel-enums)

Laravel package for Enum implementation.

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

[](#requirements)

Make sure all dependencies have been installed before moving on:

- [PHP](http://php.net/manual/en/install.php) &gt;= 7.0
- [Composer](https://getcomposer.org/download/)

Install
-------

[](#install)

Pull the package via Composer:

```
$ composer require nasyrov/laravel-enums
```

Register the service provider in `config/app.php`:

```
'providers' => [
    ...
    Nasyrov\Laravel\Enums\EnumServiceProvider::class,
    ...
]
```

Usage
-----

[](#usage)

Generate a new enum class via the command:

```
$ php artisan make:enum UserStatusEnum
```

Define the enum constants:

```
/**
 * @method static UserStatusEnum ACTIVE()
 * @method static UserStatusEnum INACTIVE()
 */
class UserStatusEnum extends Enum
{
    const ACTIVE = 10;
    const INACTIVE = 20;
}
```

To use the enum new up the instance or simply call via the static methods:

```
$status = new UserStatusEnum(UserStatusEnum::ACTIVE);
$status = UserStatusEnum::ACTIVE();
```

Type-hint the model accessor:

```
public function getStatusAttribute($attribute) {
    return new UserStatusEnum($attribute);
}
```

Type-hint the model mutator:

```
public function setStatusAttribute(UserStatusEnum $attribute) {
    $this->attributes['status'] = $attribute->getValue();
}
```

Validation:

```
$this->validate($request, [
    'status' => [
        'required',
        Rule::in(UserStatusEnum::values()),
    ],
]);
```

Localization:

```
use Nasyrov\Laravel\Enums\Enum as BaseEnum;

abstract class Enum extends BaseEnum
{
    /**
     * Get the enum labels.
     *
     * @return array
     */
    public static function labels()
    {
        return static::constants()
            ->flip()
            ->map(function ($key) {
                // Place your translation strings in `resources/lang/en/enum.php`
                return trans(sprintf('enum.%s', strtolower($key)));
            })
            ->all();
    }
}
```

```

    @foreach (UserStatusEnum::labels() as $value => $label)

            {{ $label }}

    @endforeach

```

Testing
-------

[](#testing)

```
$ composer lint
$ composer test
```

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Evgenii Nasyrov](https://github.com/nasyrov)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 60% 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 ~108 days

Recently: every ~140 days

Total

13

Last Release

2012d ago

PHP version history (2 changes)v1.0.0PHP &gt;=5.6.4

v1.1.4PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d5180ba0cd30309ada4562457c6337069906fea97f827f1c24b82fddb1bdc9a?d=identicon)[nasyrov](/maintainers/nasyrov)

---

Top Contributors

[![mrhn](https://avatars.githubusercontent.com/u/5760050?v=4)](https://github.com/mrhn "mrhn (3 commits)")[![iBotPeaches](https://avatars.githubusercontent.com/u/611784?v=4)](https://github.com/iBotPeaches "iBotPeaches (1 commits)")[![t-9](https://avatars.githubusercontent.com/u/34244217?v=4)](https://github.com/t-9 "t-9 (1 commits)")

---

Tags

enumlaravellaravel-packagephplaravelenum

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[laravel/sail

Docker files for running a basic Laravel application.

1.9k205.7M1.3k](/packages/laravel-sail)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[livewire/flux

The official UI component library for Livewire.

9527.8M127](/packages/livewire-flux)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[propaganistas/laravel-disposable-email

Disposable email validator

6023.0M6](/packages/propaganistas-laravel-disposable-email)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)

PHPackages © 2026

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