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

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

omaradel/enum
=============

An Enum package for Laravel provides an elegant and type-safe way to define and use enumerations in your Laravel application. Enumerations (Enums) are useful for representing a fixed set of constants with meaningful names, like user roles, order statuses, or payment methods.

1.0.7(8mo ago)0190MITPHPPHP ^7.2|^8.0

Since Jan 28Pushed 8mo ago1 watchersCompare

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

READMEChangelog (4)DependenciesVersions (9)Used By (0)

Laravel Enum Package
====================

[](#laravel-enum-package)

[![Latest Version](https://camo.githubusercontent.com/f66cecf0fa0e6f5ee49a5c35743fd571830f958d827750d0e98bc2a4125227e4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6f6d61726164656c2d746563682f656e756d)](https://github.com/omaradel-tech/enum/releases)[![License](https://camo.githubusercontent.com/47f530f7b0ca7aae1edf3e38dfb32605755ef2113aeaafd66b76119e44191443/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f6d61726164656c2d746563682f656e756d)](https://github.com/omaradel-tech/enum/blob/main/LICENSE)

A Laravel package that provides an easy and efficient way to work with enums in PHP, enhancing code readability and maintainability.

Features
--------

[](#features)

- **Enum Definition**: Define enums using a straightforward syntax.
- **Value Retrieval**: Retrieve enum values seamlessly.
- **Key Retrieval**: Access enum keys with ease.
- **Array Conversion**: Convert enums to arrays for flexible usage.
- **Validation Rules**: Integrate enum validation rules within Laravel's validation system.
- **Localization Support**: Support for translating enum values using Laravel's localization features.

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

[](#installation)

Install the package via Composer:

```
composer require omaradel/enum
```

Usage
-----

[](#usage)

### Defining an Enum

[](#defining-an-enum)

Create a new enum by extending the `Enum` class:

```
use omaradel\Enum\Supports\Enum;

class UserRole extends Enum
{
    const ADMIN = 'admin';
    const EDITOR = 'editor';
    const VIEWER = 'viewer';

    public static $langPath = 'enum::user_roles';
}
```

### Retrieving Enum Values

[](#retrieving-enum-values)

Access the value of an enum:

```
$adminRole = UserRole::ADMIN; // 'admin'
```

### Retrieving Enum Keys

[](#retrieving-enum-keys)

Get the key associated with a specific value:

```
$key = UserRole::ADMIN()->getKey(); // 'ADMIN'
```

### Converting Enum to Array

[](#converting-enum-to-array)

Convert the enum to an associative array:

```
$array = UserRole::toArray();
/*
[
    'ADMIN' => 'admin',
    'EDITOR' => 'editor',
    'VIEWER' => 'viewer',
]
*/
```

### Validation

[](#validation)

Use the enum in Laravel's validation rules:

```
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

public function store(Request $request)
{
    $request->validate([
        'role' => ['required', Rule::in(UserRole::values())],
    ]);

    // ...
}
```

### Localization

[](#localization)

To localize enum values, add translations in your `/lang/vendor/enum` files:

**resources/lang/vendor/enum/en/user\_roles.php:**

```
return [
    'admin' => 'Administrator',
    'editor' => 'Editor',
    'viewer' => 'Viewer',
];
```

Then, retrieve the localized value:

```
$translated = UserRole::getLabel(UserRole::ADMIN); // 'Administrator'
```

### To publish the translations files:

[](#to-publish-the-translations-files)

```
php artisan vendor:publish --tag=enum-translations
```

### Predefined Classes:

[](#predefined-classes)

1- BaseUserEnum Class:

```
use omaradel\Enum\Supports\Enum;

class BaseUserEnum extends Enum
{
    const ADMIN = 'Admin';
    const USER = 'User';
}
```

2- BaseStatusEnum Class:

```
use omaradel\Enum\Supports\Enum;

class BaseStatusEnum extends Enum
{
    const DRAFT = 'Draft';
    const PENDING = 'Pending';
    const PUBLISH = 'Published';
}
```

3- BaseUserStatusEnum Class:

```
use omaradel\Enum\Supports\Enum;

class BaseUserStatusEnum extends Enum
{
     const ACTIVE = 'Active';
    const IN_ACTIVE = 'In-Active';
}
```

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

[](#contributing)

Contributions are welcome! Please submit a pull request or open an issue to discuss improvements or features.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance61

Regular maintenance activity

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Recently: every ~57 days

Total

8

Last Release

246d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1eb508e3b76b6bc6cd83b2f1f4186fa8cd1fa3a70c457ebcd4cfcdfe7362670b?d=identicon)[omaradel-tech](/maintainers/omaradel-tech)

---

Top Contributors

[![omaradel-tech](https://avatars.githubusercontent.com/u/72930857?v=4)](https://github.com/omaradel-tech "omaradel-tech (14 commits)")

### Embed Badge

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

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

PHPackages © 2026

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