PHPackages                             weijukeji/laravel-enum-options - 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. [API Development](/categories/api)
4. /
5. weijukeji/laravel-enum-options

ActiveLibrary[API Development](/categories/api)

weijukeji/laravel-enum-options
==============================

A Laravel package for handling enums with frontend-friendly options (labels, colors, icons) and multi-language support

v1.4.0(2mo ago)031↓80%1MITPHPPHP ^8.1

Since Dec 18Pushed 2mo agoCompare

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

READMEChangelogDependencies (8)Versions (8)Used By (1)

Laravel Enum Options
====================

[](#laravel-enum-options)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6c6bfcb77b2a362362eb2f35227f7071a4af6596f57c027ed812fc1f662549db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765696a756b656a692f6c61726176656c2d656e756d2d6f7074696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weijukeji/laravel-enum-options)[![Total Downloads](https://camo.githubusercontent.com/2071373c9a2896c7a2ab91802b4263c034b7053abbbad3bc1dbea14443ee8106/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765696a756b656a692f6c61726176656c2d656e756d2d6f7074696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weijukeji/laravel-enum-options)[![License](https://camo.githubusercontent.com/b08bceace09bc17861ab51a704bbd20305f752ccb46e23164d65f8838ca40198/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7765696a756b656a692f6c61726176656c2d656e756d2d6f7074696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weijukeji/laravel-enum-options)

English | [简体中文](README.zh-CN.md)

A Laravel package for handling enums with frontend-friendly options (labels, colors, icons) and multi-language support.

Features
--------

[](#features)

- 🎨 **Frontend-Friendly**: Built-in support for labels, colors, and icons
- 🌍 **Multi-Language**: Full i18n support with fallback mechanism
- 📦 **Preset Enums**: 10+ ready-to-use enum classes for common scenarios
- 🎯 **Flexible**: Use presets as-is, publish and customize, or create your own
- ⚙️ **Configurable**: Override labels and colors without modifying enum classes
- 🛠️ **Artisan Commands**: Generate, publish, and list enums with ease
- 🔄 **Resource Integration**: Works seamlessly with Laravel API Resources

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

[](#requirements)

- PHP 8.1+
- Laravel 10.x, 11.x, 12.x, or 13.x

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

[](#installation)

Install the package via Composer:

```
composer require weijukeji/laravel-enum-options
```

Publish the configuration file (optional):

```
php artisan vendor:publish --tag=enum-options-config
```

Quick Start
-----------

[](#quick-start)

### Using Preset Enums

[](#using-preset-enums)

Use built-in preset enums directly:

```
use WeiJuKeJi\EnumOptions\Presets\Payment\PaymentMethodEnum;

$method = PaymentMethodEnum::WECHAT;
echo $method->label();  // 微信支付
echo $method->color();  // green
echo $method->icon();   // wechat

// Get all options for dropdown
$options = PaymentMethodEnum::options();
// [
//     ['value' => 'wechat', 'label' => '微信支付', 'color' => 'green', 'icon' => 'wechat'],
//     ['value' => 'alipay', 'label' => '支付宝', 'color' => 'blue', 'icon' => 'alipay'],
//     ...
// ]
```

### Publishing Presets to Your App

[](#publishing-presets-to-your-app)

Publish preset enums to customize them:

```
# Publish a specific preset
php artisan enum:publish PaymentMethod

# Publish all presets
php artisan enum:publish --all

# Publish with translation files
php artisan enum:publish PaymentMethod --with-translations
```

The enum will be published to `app/Enums/PaymentMethodEnum.php` and you can freely modify it.

### Creating Custom Enums

[](#creating-custom-enums)

Create your own enum from scratch:

```
php artisan make:enum SubscriptionStatus --values=active,paused,cancelled --labels
```

This generates:

```
