PHPackages                             mindtwo/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. mindtwo/laravel-enum

Abandoned → [bensampo/laravel-enum](/?search=bensampo%2Flaravel-enum)ArchivedLibrary[Validation &amp; Sanitization](/categories/validation)

mindtwo/laravel-enum
====================

Simple, extensible and powerful enumeration implementation for Laravel.

2.1.0(6y ago)0671MITPHPPHP ~7.1

Since Sep 7Pushed 6y agoCompare

[ Source](https://github.com/mindtwo/laravel-enum)[ Packagist](https://packagist.org/packages/mindtwo/laravel-enum)[ Docs](https://github.com/bensampo/laravel-enum)[ RSS](/packages/mindtwo-laravel-enum/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (5)Versions (42)Used By (1)

[![Laravel Enum](https://github.com/BenSampo/laravel-enum/raw/master/branding/logo.svg?sanitize=true)](https://github.com/BenSampo/laravel-enum/raw/master/branding/logo.svg?sanitize=true)

[![Build Status](https://camo.githubusercontent.com/a1c7cc93707cec45e18bed45a1c24056af47582dac99b25c61e40f64a876d495/68747470733a2f2f7472617669732d63692e6f72672f42656e53616d706f2f6c61726176656c2d656e756d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/BenSampo/laravel-enum)[![Packagist Stable Version](https://camo.githubusercontent.com/37e4ba93fe82ee3127db4edf198c5eb6c8ae15db3998e00dc142aff7e20fdfe3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62656e73616d706f2f6c61726176656c2d656e756d2e7376673f7374796c653d666c61742d737175617265266c6162656c3d737461626c65)](https://packagist.org/packages/bensampo/laravel-enum)[![Packagist downloads](https://camo.githubusercontent.com/5dfbbbf42864601ee53a411992e273dd66f7fe90374b775f0582df93d493277d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62656e73616d706f2f6c61726176656c2d656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bensampo/laravel-enum)[![MIT Software License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

About Laravel Enum
------------------

[](#about-laravel-enum)

Simple, extensible and powerful enumeration implementation for Laravel.

- Enum key value pairs as class constants
- Full featured suite of methods
- Enum instantiation
- Type hinting
- Attribute casting
- Enum artisan generator
- Validation rules for passing enum key or values as input parameters
- Localization support
- Extendable via Macros

Created by [Ben Sampson](https://sampo.co.uk)

Jump To
-------

[](#jump-to)

- [Guide](#guide)
- [Installation](#installation)
- [Enum Library](enum-library.md)
- [Basic Usage](#basic-usage)
    - [Enum definition](#enum-definition)
    - [Instantiation](#instantiation)
    - [Instance Properties](#instance-properties)
    - [Instance Equality](#instance-equality)
    - [Type Hinting](#instance-equality)
- [Attribute Casting](#attribute-casting)
- [Validation](#validation)
- [Localization](#localization)
- [Overriding the getDescription method](#overriding-the-getdescription-method)
- [Extending the Enum Base Class](#extending-the-enum-base-class)
- [PHPStan Integration](#phpstan-integration)
- [Artisan Command List](#artisan-command-list)
- [Enum Class Reference](#enum-class-reference)

Guide
-----

[](#guide)

I wrote a blog post about using laravel-enum:

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

[](#requirements)

- Laravel `5.4` or newer
- PHP `7.1` or newer

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

[](#installation)

Via Composer

```
composer require bensampo/laravel-enum
```

If you're using Laravel &lt; 5.5 you'll need to add the service provider to `config/app.php`

```
'BenSampo\Enum\EnumServiceProvider'
```

Enum Library
------------

[](#enum-library)

Browse and download from a list of commonly used, community contributed enums.

[Enum library →](enum-library.md)

Basic Usage
-----------

[](#basic-usage)

### Enum Definition

[](#enum-definition)

You can use the following Artisan command to generate a new enum class:

```
php artisan make:enum UserType
```

Now, you just need to add the possible values your enum can have as constants.

```
