wboyz / laravel-enum by nalatreb

Base enum class with some features.
1,951
6
3
Package Data
Maintainer Username: nalatreb
Maintainer Contact: bertalan.verebelyi@gmail.com (Bertalan Verebelyi)
Package Create Date: 2016-04-02
Package Last Update: 2016-04-19
Language: PHP
License: MIT
Last Refreshed: 2020-08-01 03:02:43
Package Statistics
Total Downloads: 1,951
Monthly Downloads: 18
Daily Downloads: 1
Total Stars: 6
Total Watchers: 3
Total Forks: 2
Total Open Issues: 0

Laravel Enum

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