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

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

kminek/laravel-enum
===================

Use myclabs/php-enum as Eloquent model attributes

v1.0.0(4y ago)05MITPHPPHP &gt;=8.0.0

Since Sep 15Pushed 4y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Laravel Enum
============

[](#laravel-enum)

Use most popular enum implementation for PHP
[myclabs/php-enum](https://github.com/myclabs/php-enum) as Eloquent model attributes.

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

[](#installation)

```
composer require kminek/laravel-enum
```

Usage
-----

[](#usage)

Instead of using base enum class from `myclabs/php-enum`:

```
use \MyCLabs\Enum\Enum;

class Brand extends Enum
{
    public const TOYOTA = 'toyota';
    public const BMW = 'bmw';
    public const PEUGEOT = 'peugeot';
}
```

use enum class from this package:

```
use \Kminek\LaravelEnum\Enum;

class Brand extends Enum
{
    public const TOYOTA = 'toyota';
    public const BMW = 'bmw';
    public const PEUGEOT = 'peugeot';
}
```

Setup model attribute to use enum class:

```
class Car extends \Illuminate\Database\Eloquent\Model
{
    protected $casts = [
        'brand' => Brand::class,
    ];
}
```

If you would like to allow `null` values also:

```
class Car extends \Illuminate\Database\Eloquent\Model
{
    protected $casts = [
        'brand' => Brand::class.':nullable',
    ];
}
```

From now on you can get/set enums:

```
// set
$car = new Car();
$car->brand = new Brand(Brand::BMW);
// or
$car->brand = Brand::BMW;

// get
$brand = $car->brand; // $brand is enum instance
```

Running tests
-------------

[](#running-tests)

```
composer test
```

Coding standards fixer
----------------------

[](#coding-standards-fixer)

```
composer cs
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

Unknown

Total

1

Last Release

1698d ago

### Community

Maintainers

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

---

Top Contributors

[![kminek](https://avatars.githubusercontent.com/u/373962?v=4)](https://github.com/kminek "kminek (2 commits)")

---

Tags

laravelenum

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[silber/bouncer

Eloquent roles and abilities.

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

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

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

423715.4k1](/packages/clickbar-laravel-magellan)[larapack/doctrine-support

Better Doctrine Support with Laravel (Support for `enum`)

1752.3M55](/packages/larapack-doctrine-support)

PHPackages © 2026

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