lazerg/laravel-enum-pro

A powerful PHP enum extension with collection support, random selection, and magic static calls

Installs: 18 518

Dependents: 0

Suggesters: 0

Security: 0

Stars: 43

Watchers: 2

Forks: 2

Open Issues: 1

pkg:composer/lazerg/laravel-enum-pro

v0.7.0 2026-01-28 17:33 UTC

This package is auto-updated.

Last update: 2026-01-28 17:36:30 UTC


README

Laravel Enum Pro

Latest Version PHP Version Downloads Total Downloads Packagist Stars

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.

Installation

composer require lazerg/laravel-enum-pro

Enum Example

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

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

Accessing Value

// 1
DifficultyEnum::VERY_EASY();

// 3
DifficultyEnum::MEDIUM();

// 5
DifficultyEnum::VERY_STRONG();

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

Accessing Name

// ['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);

Accessing Values

// [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');

Accessing Options

// [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();

Accessing Random Value

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

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

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

Testing

./vendor/bin/pest

License

This package is open-sourced software licensed under the MIT license.