PHPackages                             splitstack/laravel-enum-friendly - 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. splitstack/laravel-enum-friendly

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

splitstack/laravel-enum-friendly
================================

Make your Laravel enums friendly with TypeScript, selects, and many more convenient features

2.1.0(1mo ago)03.6k↑656.7%MITPHPPHP ^8.1CI passing

Since Apr 1Pushed 1mo ago1 watchersCompare

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

READMEChangelog (4)Dependencies (10)Versions (4)Used By (0)

EnumFriendly for Laravel
========================

[](#enumfriendly-for-laravel)

[![Tests](https://camo.githubusercontent.com/74ce33d9b283fe2a01cb28d7a702e16f8bf84f6b5f677034d79bb591634afafe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656d696c69656e6b6f70702f456e756d467269656e646c792f74657374732e796d6c3f6c6162656c3d7465737473)](https://camo.githubusercontent.com/74ce33d9b283fe2a01cb28d7a702e16f8bf84f6b5f677034d79bb591634afafe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656d696c69656e6b6f70702f456e756d467269656e646c792f74657374732e796d6c3f6c6162656c3d7465737473)

[![PHP Version](https://camo.githubusercontent.com/c3d372b55ac2d4fcf386a178e11d9788310097b35f3893cf3daae574b6b4cd3e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c75652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/c3d372b55ac2d4fcf386a178e11d9788310097b35f3893cf3daae574b6b4cd3e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c75652e7376673f7374796c653d666c61742d737175617265)[![Laravel Version](https://camo.githubusercontent.com/e06d835966e2c7d5e5f60b16d88a3ec1f1d16c0f58667b981d4a769a66a28859/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d25354531312e302d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/e06d835966e2c7d5e5f60b16d88a3ec1f1d16c0f58667b981d4a769a66a28859/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d25354531312e302d6f72616e67652e7376673f7374796c653d666c61742d737175617265)[![Total Downloads](https://camo.githubusercontent.com/66c08c4b883838f2b023e8cc5e42e7da46e0dccbb77743e143dce98fe76eaa09/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73706c6974737461636b2f6c61726176656c2d656e756d2d667269656e646c792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/splitstack/laravel-enum-friendly)

Introduction
------------

[](#introduction)

EnumFriendly for Laravel is a powerful PHP package that enhances your Laravel application's enum experience. Built on top of the dependency-free [EnumFriendly Core](https://github.com/EmilienKopp/EnumFriendlyCore), it provides Laravel-specific features like Collections, validation rules, and Artisan commands while maintaining all the core functionality.

**🚀 Key Features:**

- **Laravel Collections Integration** - Many methods return Laravel Collections for fluent chaining
- **Artisan Commands** - Generate enum classes with a simple command
- **Laravel Validation** - Automatic validation rule generation and Laravel Rule integration
- **Comprehensive Enum Utilities** - Over 25 helpful methods for enum manipulation
- **TypeScript Integration** - Generate TypeScript-compatible type definitions
- **Form Integration** - Ready-made select options with Laravel Collections
- **Developer Friendly** - Intuitive API with extensive documentation

With EnumFriendly for Laravel, you can:

- Generate enum classes with a simple artisan command
- Convert enum values to TypeScript types
- Create form-friendly select options with Laravel Collections
- Generate Laravel validation rules automatically
- Access readable labels and collections
- Use all core EnumFriendly features with Laravel enhancements
- And much more!

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

[](#installation)

You can install the package via composer:

```
composer require splitstack/laravel-enum-friendly
```

The package will automatically register its service provider and install the dependency-free core package.

Laravel-Specific Features
-------------------------

[](#laravel-specific-features)

### Artisan Commands

[](#artisan-commands)

Generate enum classes with the `MakeFriendlyEnum` command:

```
php artisan split:enum {name} {--type= : string or int, the backed type} {--u|upper : Convert the case name to uppercase} {values*}
```

Example:

```
php artisan split:enum Status --type=string active:ACTIVE inactive:INACTIVE
```

This will create an enum `Status` with the following cases and the `ExtendedEnum` trait:

```
use Splitstack\EnumFriendly\Traits\ExtendedEnum;

enum Status: string
{
  use ExtendedEnum;

  case ACTIVE = 'active';
  case INACTIVE = 'inactive';
}
```

### Laravel Collections Integration

[](#laravel-collections-integration)

The Laravel package extends several core methods to return Laravel Collections instead of arrays:

```
// Returns Laravel Collection instead of array
Status::collect(); // Collection of ['active', 'inactive']
Status::toSelectOptions(); // Collection of select option arrays
```

### Laravel Validation Rules

[](#laravel-validation-rules)

Generate Laravel validation rules automatically:

```
Status::rules(['required']);
// Returns: ['required', 'string', 'in:active,inactive']

// Or get a Laravel Rule instance
Status::rule();
// Returns: Illuminate\Validation\Rules\Enum instance
```

Usage
-----

[](#usage)

### Adding the ExtendedEnum Trait

[](#adding-the-extendedenum-trait)

Simply add the `ExtendedEnum` trait to your existing enums to unlock all the enhanced functionality:

```
