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 DifficultyEnum: int
{
    use \Lazerg\LaravelEnumPro\EnumPro;

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

// 1
DifficultyEnum::VERY_EASY();

// 3
DifficultyEnum::MEDIUM();

// 5
DifficultyEnum::VERY_STRONG();

// 3
$enum = DifficultyEnum::MEDIUM;
$enum();

// ['VERY_EASY', 'EASY', 'MEDIUM', 'STRONG', 'VERY_STRONG']
DifficultyEnum::namesToArray();

// 'VERY_EASY, EASY, MEDIUM, STRONG, VERY_STRONG'
DifficultyEnum::namesToString();

// Collection(['VERY_EASY', 'EASY', 'MEDIUM', 'STRONG', 'VERY_STRONG'])
DifficultyEnum::names();

// 'MEDIUM'
DifficultyEnum::nameOf(3);

// [1, 2, 3, 4, 5]
DifficultyEnum::valuesToArray();

// '1,2,3,4,5'
DifficultyEnum::valuesToString();

// Collection([1, 2, 3, 4, 5])
DifficultyEnum::values();

// 1
DifficultyEnum::valueOf('VERY_EASY');

// 3 (case-insensitive)
DifficultyEnum::valueOf('medium');

// 5 (spaces converted to underscores)
DifficultyEnum::valueOf('Very strong');

// [1 => 'Very Easy', 2 => 'Easy', 3 => 'Medium', 4 => 'Strong', 5 => 'Very Strong']
DifficultyEnum::optionsToArray();

// Collection([1 => 'Very Easy', 2 => 'Easy', 3 => 'Medium', 4 => 'Strong', 5 => 'Very Strong'])
DifficultyEnum::options();

// 'Very Strong'
DifficultyEnum::getOption(5);

// ['Medium', 'Very Strong']
DifficultyEnum::getOptions([3, 5]);

// [['value' => 1, 'display' => 'Very Easy'], ['value' => 2, 'display' => 'Easy'], ...]
DifficultyEnum::selectionsToArray();

// Collection([['value' => 1, 'display' => 'Very Easy'], ['value' => 2, 'display' => 'Easy'], ...])
DifficultyEnum::selections();

// [3, 1] (random values)
DifficultyEnum::randomArray(2);

// 4 (single random value)
DifficultyEnum::randomFirst();

// Collection([2, 5, 1]) (random values)
DifficultyEnum::random(3);