PHPackages                             jundayw/laravel-enumeration - 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. jundayw/laravel-enumeration

ActiveLibrary

jundayw/laravel-enumeration
===========================

The Laravel Enumeration.

v0.6.0(3y ago)03MITPHPPHP &gt;=8.1.0

Since Aug 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/jundayw/laravel-enumeration)[ Packagist](https://packagist.org/packages/jundayw/laravel-enumeration)[ RSS](/packages/jundayw-laravel-enumeration/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

安装方法
====

[](#安装方法)

命令行下, 执行 composer 命令安装:

```
composer require jundayw/laravel-enumeration
```

命令行
===

[](#命令行)

发布配置文件
------

[](#发布配置文件)

```
php artisan vendor:publish --tag=enumeration
```

生成
--

[](#生成)

```
php artisan make:enumeration Test
```

使用方法
====

[](#使用方法)

枚举配置
----

[](#枚举配置)

```
namespace App\Enums;

use Jundayw\LaravelEnumeration\Annotation\Attributes;
use Jundayw\LaravelEnumeration\Concerns\HasEnumeration;
use Jundayw\LaravelEnumeration\Contracts\Enumeration;

enum Test: string implements Enumeration
{
    use HasEnumeration;

    #[Attributes(attribute: '正常')]
    case NORMAL = 'NORMAL';
    #[Attributes(attribute: '禁用')]
    case DISABLE = 'DISABLE';
    #[Attributes(attribute: 'Attribute')]
    case NAME = 'VALUE';

}
```

模型配置
----

[](#模型配置)

```
namespace App\Models;

use App\Enums\Test;
use Illuminate\Database\Eloquent\Model;

class Manager extends Model
{
    /**
     * @var string[]
     */
    protected $casts = [
        'state' => Test::class,
    ];

}
```

枚举集合
----

[](#枚举集合)

```
use App\Enums\Test;

dd(Test::cases());
dd(Test::values());
```

修改器
---

[](#修改器)

```
use App\Enums\Test;
use App\Models\Manager;

$manager = new Manager();
$manager->state = Test::NAME;
$manager->state = Test::from('VALUE');
$manager->state = Test::valueOf('value')->getDeclaringClass();
$manager->state = Test::valueOf('VALUE')->getDeclaringClass();
$manager->state = Test::valueOf('VALUE')->getDeclaringClass()->value;
```

拾取器
---

[](#拾取器)

```
use App\Enums\Test;
use App\Models\Manager;

$manager = (new Manager())->find(1);;
dd($manager->state);
```

枚举方法集合
------

[](#枚举方法集合)

```
use App\Enums\Test;
use Jundayw\LaravelEnumeration\Annotation\Attributes;

dd([
    // Test[]
    Test::cases(),
    // string
    Test::NAME->name,
    // string
    Test::NAME->getName(),
    // string
    Test::NAME->value,
    // string
    Test::NAME->getValue(),
    // mixed
    Test::NAME->getAttribute(),
    // array
    Test::NAME->toArray(),
    // string
    Test::NAME->toJson(),
    // Attributes[]
    Test::values(),
    // string
    Test::valueOf('NAME', Test::NAME)->name,
    // string
    Test::valueOf('NAME', Test::NAME)->getName(),
    // string
    Test::valueOf('NAME', Test::NAME)->value,
    // string
    Test::valueOf('NAME', Test::NAME)->getValue(),
    // mixed
    Test::valueOf('NAME', Test::NAME)->getAttribute(),
    // string
    Test::valueOf('value')->name,
    // string
    Test::valueOf('value')->getName(),
    // string
    Test::valueOf('value')->value,
    // string
    Test::valueOf('value')->getValue(),
    // mixed
    Test::valueOf('value')->getAttribute(),
    // Test
    Test::valueOf('value')->getDeclaringClass(),
    // string
    Test::valueOf('value')->getDeclaringClass()->name,
    // string
    Test::valueOf('value')->getDeclaringClass()->getName(),
    // string
    Test::valueOf('value')->getDeclaringClass()->value,
    // string
    Test::valueOf('value')->getDeclaringClass()->getValue(),
    // mixed
    Test::valueOf('value')->getDeclaringClass()->getAttribute(),
]);
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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

Every ~0 days

Total

2

Last Release

1371d ago

### Community

Maintainers

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

---

Top Contributors

[![jundayw](https://avatars.githubusercontent.com/u/16873970?v=4)](https://github.com/jundayw "jundayw (3 commits)")

---

Tags

laravelenumeration

### Embed Badge

![Health badge](/badges/jundayw-laravel-enumeration/health.svg)

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

###  Alternatives

[cerbero/laravel-enum

Laravel package to supercharge enum functionalities.

18989.6k](/packages/cerbero-laravel-enum)[emreyarligan/enum-concern

A PHP package for effortless Enumeration handling with Laravel Collections 📦 ✨

21156.3k1](/packages/emreyarligan-enum-concern)[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

394388.0k5](/packages/rtconner-laravel-likeable)[hemp/presenter

Easy Model Presenters in Laravel

247592.6k1](/packages/hemp-presenter)[slowlyo/owl-admin

基于 laravel、amis 开发的后台框架~

61214.2k26](/packages/slowlyo-owl-admin)

PHPackages © 2026

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