A powerful trait that supercharges PHP 8.1+ enums with Laravel-friendly utilities. Get values, names, random cases, and form-ready options with a clean, fluent API.
composer require lazerg/laravel-enum-proenum 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);./vendor/bin/pestThis package is open-sourced software licensed under the MIT license.
