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

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

desmart/laravel-enum
====================

PHP enums for Laravel models

1.1.0(5y ago)0426MITPHPPHP ^7.4|^8.0

Since Mar 8Pushed 5y ago5 watchersCompare

[ Source](https://github.com/DeSmart/laravel-enum)[ Packagist](https://packagist.org/packages/desmart/laravel-enum)[ RSS](/packages/desmart-laravel-enum/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (6)Versions (4)Used By (0)

PHP enums for Laravel models 📚
==============================

[](#php-enums-for-laravel-models-)

[![Latest version](https://camo.githubusercontent.com/0a042dd981efa71a7e5ae65258edb1da8f058a5b4a2cd7512433dcba1f195ca5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465736d6172742f6c61726176656c2d656e756d2e7376673f7374796c653d666c6174)](https://github.com/DeSmart/laravel-enum)[![Tests](https://github.com/desmart/laravel-enum/workflows/Run%20Tests/badge.svg)](https://github.com/desmart/laravel-enum/workflows/Run%20Tests/badge.svg)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](https://github.com/DeSmart/laravel-enum/blob/master/LICENSE)

Package provides a simple way to use strongly typed enum objects with Laravel models. It utilizes Laravel's custom casting mechanism.

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

[](#installation)

To install the package via Composer, simply run the following command:

```
composer require desmart/laravel-enum
```

Usage
-----

[](#usage)

Create an enum class that extends `DeSmart\Laravel\Enumeration`. Then, simply define all possible values in form of class constants:

```
class Character extends DeSmart\Laravel\Enumeration
{
    const GOOD = 'good';
    const EVIL = 'evil';
    const SOMETIMES_GOOD_SOMETIMES_EVIL = 'sometimes_good_sometimes_evil';
}
```

In Laravel model:

```
class Hero extends Model
{
    /**
     * @var array
     */
    protected $casts = [
        'character' => Character::class,
    ];
}
```

That's it.

```
$hero = new Hero(['character' => Character::EVIL]);

dump($hero);
// Hero {#293
//  ...
//  #casts: array:1 [
//    "character" => "Character"
//  ]
// ...
//  #attributes: array:1 [
//    "character" => "evil"
//  ]
// }

dump($hero->character);
// Character {#296
//  -value: "evil"
// }
```

### Enumeration class generation

[](#enumeration-class-generation)

Package provides `make:enum` Artisan command for enumeration classes auto-generation. To generate new enum class, run:

```
php artisan make:enum Character --cases='good,evil,sometimes_good_sometimes_evil'
```

> `--cases` (or `-c`) option allows defining available enum cases. Command can be run without that option specified.

Above command will create a new class inside `Enums` directory:

```
namespace App\Enums;

use DeSmart\Laravel\Enumeration\Enumeration;

/**
 * @method static Character good()
 * @method static Character evil()
 * @method static Character sometimesGoodSometimesEvil()
 */
class Character extends Enumeration
{
	const GOOD = 'good';
	const EVIL = 'evil';
	const SOMETIMES_GOOD_SOMETIMES_EVIL = 'sometimes_good_sometimes_evil';
}
```

Changelog
---------

[](#changelog)

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

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

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

Total

2

Last Release

1934d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a3c56cab812fc073277f1e127a12e0c6066565dc57bd3045484fcca1901021b?d=identicon)[gollum](/maintainers/gollum)

---

Top Contributors

[![golonix](https://avatars.githubusercontent.com/u/9950778?v=4)](https://github.com/golonix "golonix (12 commits)")

---

Tags

phplaravelenummodelenumerationenumsdesmart

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

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

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.5k55.4M8.4k](/packages/larastan-larastan)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[api-platform/laravel

API Platform support for Laravel

58170.8k14](/packages/api-platform-laravel)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

15118.7k4](/packages/calebdw-larastan)

PHPackages © 2026

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