PHP code example of lazerg / laravel-enum-pro

1. Go to this page and download the library: Download lazerg/laravel-enum-pro library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lazerg / laravel-enum-pro example snippets


enum LevelTypes: int
{
    use \Lazerg\LaravelEnumPro\EnumPro;

    case VERY_EASY = 1;
    case EASY = 2;
    case MEDIUM = 3;
    case STRONG = 4;
    case VERY_STRONG = 5;
}

LevelTypes::VERY_EASY();          // 1
LevelTypes::valueOf('very easy'); // 1

LevelTypes::names();         // Collection: ['VERY_EASY', 'EASY', 'MEDIUM', 'STRONG', 'VERY_STRONG']
LevelTypes::namesToArray();  // ['VERY_EASY', 'EASY', 'MEDIUM', 'STRONG', 'VERY_STRONG']
LevelTypes::namesToString(); // "VERY_EASY, EASY, MEDIUM, STRONG, VERY_STRONG"
LevelTypes::nameOf(1);       // 'VERY_EASY'

LevelTypes::values();         // Collection: [1, 2, 3, 4, 5]
LevelTypes::valuesToArray();  // [1, 2, 3, 4, 5]
LevelTypes::valuesToString(); // "1,2,3,4,5"

LevelTypes::random();      // Collection with one random value
LevelTypes::randomArray(); // Array with one random value
LevelTypes::randomFirst(); // Single random value

LevelTypes::options();       // Collection of [value => display]
LevelTypes::optionsToArray();
LevelTypes::selections();    // Collection of [value => ..., display => ...]
LevelTypes::selectionsToArray();

Illuminate\Support\Collection {
    #items: [
        1 => "Very Easy",
        2 => "Easy",
        3 => "Medium",
        4 => "Strong",
        5 => "Very Strong",
    ]
}