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::names();         // Collection: ['VERY_EASY', 'EASY', 'MEDIUM', 'STRONG', 'VERY_STRONG']
LevelTypes::namesToArray();  // Array: ['VERY_EASY', 'EASY', 'MEDIUM', 'STRONG', 'VERY_STRONG']
LevelTypes::namesToString(); // String: VERY_EASY, EASY, MEDIUM, STRONG, VERY_STRONG
LevelTypes::nameOf(1);       // String: VERY_EASY

LevelTypes::values();         // Collection: [1, 2, 3, 4, 5]
LevelTypes::valuesToArray();  // Array: [1, 2, 3, 4, 5]
LevelTypes::valuesToString(); // String: 1, 2, 3, 4, 5
LevelTypes::valueOf('very easy'); // 1

LevelTypes::random(int $count = 1);      // Collection of $count random values
LevelTypes::randomArray(int $count = 1); // Array of $count random values
LevelTypes::randomFirst();               // One random value

LevelTypes::options(); // Return collection of selectable options
LevelTypes::optionsToArray(); // Return array of selectable options

LevelTypes::selections();
LevelTypes::selectionsToArray();
bash
Illuminate\Support\Collection {#7777
    #items: array:5 [
        1 => "Very Easy"
        2 => "Easy"
        3 => "Medium"
        4 => "Strong"
        5 => "Very Strong"
    ]
}
bash
Illuminate\Support\Collection {#7777
    #items: array:5 [
        0 => [
            "value"   => "1",
            "display" => "Very Easy",
        ],
        1 => [
            "value"   => "2",
            "display" => "Easy",
        ],
        2 => [
            "value"   => "3",
            "display" => "Medium",
        ],
        3 => [
            "value"   => "4",
            "display" => "Strong",
        ],
        4 => [
            "value"   => "5",
            "display" => "Very Strong",
        ],
    ]
}