PHPackages                             orkhanahmadov/eloquent-enum-cast - 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. [Database &amp; ORM](/categories/database)
4. /
5. orkhanahmadov/eloquent-enum-cast

ActiveLibrary[Database &amp; ORM](/categories/database)

orkhanahmadov/eloquent-enum-cast
================================

Enum cast for Eloquent

1.4.0(4y ago)51.8k1MITPHPPHP ^7.3|^8.0

Since Aug 3Pushed 4y ago1 watchersCompare

[ Source](https://github.com/orkhanahmadov/eloquent-enum-cast)[ Packagist](https://packagist.org/packages/orkhanahmadov/eloquent-enum-cast)[ Docs](https://github.com/orkhanahmadov/eloquent-enum-cast)[ RSS](/packages/orkhanahmadov-eloquent-enum-cast/feed)WikiDiscussions master Synced yesterday

READMEChangelog (8)Dependencies (5)Versions (9)Used By (0)

Enum cast for Eloquent
======================

[](#enum-cast-for-eloquent)

[![Latest Version on Packagist](https://camo.githubusercontent.com/52fcb32f14c5b9ad884e8050493c6b6e217321dad8f78717036bce4d793224cc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f726b68616e61686d61646f762f656c6f7175656e742d656e756d2d636173742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/orkhanahmadov/eloquent-enum-cast)[![Total Downloads](https://camo.githubusercontent.com/021d621b933d530a07a5f319db5a2338dd5471abf07d4a535c8d51f63a98b162/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f726b68616e61686d61646f762f656c6f7175656e742d656e756d2d636173742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/orkhanahmadov/eloquent-enum-cast)[![GitHub Actions](https://github.com/orkhanahmadov/eloquent-enum-cast/actions/workflows/main.yml/badge.svg)](https://github.com/orkhanahmadov/eloquent-enum-cast/actions/workflows/main.yml/badge.svg)

Simple Enum cast for Eloquent ORM using [myclabs/php-enum](https://github.com/myclabs/php-enum).

Important!
----------

[](#important)

Since the release of PHP 8.1 this package is no longer maintained!

With PHP 8.1 you should use native enums and as of Laravel [v8.71.0](https://github.com/laravel/framework/releases/tag/v8.71.0) Eloquent has official support to cast from and to native backed enums.

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

[](#requirements)

- **PHP ^7.3** or **PHP ^8.0**
- **Laravel 8.0** or higher

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

[](#installation)

You can install the package via composer:

```
composer require orkhanahmadov/eloquent-enum-cast
```

Usage
-----

[](#usage)

Let's say you have following Enum class using [myclabs/php-enum](https://github.com/myclabs/php-enum).

```
namespace App\Enums;

use MyCLabs\Enum\Enum;

class Role extends Enum
{
    private const ADMIN = 1;
    private const USER = 2;
}
```

To make it Eloquent castable, instead of `MyCLabs\Enum\Enum`, extend from `Orkhanahmadov\EloquentEnumCast\EnumCast`

```
namespace App\Enums;

use Orkhanahmadov\EloquentEnumCast\EnumCast;

class Role extends EnumCast
{
    private const ADMIN = 1;
    private const USER = 2;
}
```

> Note: `Orkhanahmadov\EloquentEnumCast\EnumCast` extends `MyCLabs\Enum\Enum`, you can still use any other methods and properties that it has.

Finally, in your Eloquent model cast attribute using your Enum class

```
use App\Enums\Role;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    protected $casts = [
        'role' => Role::class,
    ];
}
```

Now Eloquent will cast raw database values to your `App\Enums\Role` enum whenever you retrieve User model from database.

Likewise, whenever you save User model with `App\Enums\Role` enum as `role` attribute Eloquent will automatically save enum's underlying value into database.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

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

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

[](#contributing)

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

### Security

[](#security)

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

Credits
-------

[](#credits)

- [Orkhan Ahmadov](https://github.com/orkhanahmadov)
- [Michael Thaller](https://github.com/mThallerWeb)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

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

Recently: every ~42 days

Total

8

Last Release

1545d ago

PHP version history (3 changes)1.0.0PHP ^7.4|^8.0

1.0.2PHP ^7.3|^8.0

1.3.0PHP ^7.3|8.0.\*

### Community

Maintainers

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

---

Top Contributors

[![orkhanahmadov](https://avatars.githubusercontent.com/u/7041590?v=4)](https://github.com/orkhanahmadov "orkhanahmadov (19 commits)")

---

Tags

laraveleloquenteloquent-enum-cast

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/orkhanahmadov-eloquent-enum-cast/health.svg)

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

###  Alternatives

[silber/bouncer

Eloquent roles and abilities.

3.6k4.4M25](/packages/silber-bouncer)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)

PHPackages © 2026

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