wboyz/laravel-enum

Base enum class with some features.

Installs: 11 870

Dependents: 0

Suggesters: 0

Security: 0

Stars: 8

Watchers: 4

Forks: 2

Open Issues: 0

Type:helper

v0.2.1 2016-04-19 12:29 UTC

This package is auto-updated.

Last update: 2024-10-29 04:31:08 UTC


README

License Latest Stable Version

Create a base enum class to laravel framework.

Installation

Require this package with composer:

composer require wboyz/laravel-enum

General Use

use WBoyz\LaravelEnum\BaseEnum;

class Fruits extends BaseEnum
{
    const APPLE = 1;
    const PEACH = 2;
    const PEAR = 3;
}

...

$values = Fruits::getValues();
// [1, 2, 3]

$keys = Fruits::getKeys();
// ['APPLE', 'PEACH', 'PEAR']

$dictionary = Fruits::toDictionary();
// ['APPLE' => 1, 'PEACH' => 2, 'PEAR' => 3]

$result = Fruits::hasValue(1);  
// true

$result = Fruits::hasKey('APPLE');
// true

$result = Fruits::getValue('APPLE');
// 1

$result = Fruits::getValue('MELON');
// 0