Search by

roundly-consulting / enums-for-laravel

mihaliak

Convenient helper methods for PHP enums in Laravel applications

Package info

github.com/roundly-consulting/enums-for-laravel

pkg:composer/roundly-consulting/enums-for-laravel

Fund package maintenance!

Patreon

Statistics

Installs: 231

Dependents: 38

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-10-03 17:48 UTC

This package is auto-updated.

Last update: 2026-10-03 17:52:24 UTC


README

Enums for Laravel — Roundly open source

Latest release Tests Code style Donate Patreon Crypto

Enums for Laravel

Helper methods for PHP enums in Laravel. Drop the Helpers trait into an enum to get translated labels, names/values/labels lists, select-ready options, case lookups, a validation rule, random selection, equality checks and conditional callbacks — for backed and pure enums alike.

Installation

Requires PHP 8.4, Laravel 12 or 13.

composer require roundly-consulting/enums-for-laravel

Usage

Add the Helpers trait to any enum:

use RoundlyConsulting\Enums\Helpers;

enum NewsCategory: string
{
    use Helpers;

    case HotNews = 'hot-news';
    case RegularNews = 'regular-news';
    case PrivateNews = 'private-news';
}

Then use it for labels, selects, validation and lookups:

NewsCategory::HotNews->label();         // "Hot News", translated through lang/*.json
NewsCategory::values()->all();          // ['hot-news', 'regular-news', 'private-news']
NewsCategory::toArray();                // ['hot-news' => 'Hot News', …] for a <select>
NewsCategory::options();                // EnumOption DTOs: value, label, name

$request->validate([
    'category' => ['required', NewsCategory::validationRule()],   // 'in:hot-news,regular-news,private-news'
]);

NewsCategory::fromLabel('Hot News');    // NewsCategory::HotNews
NewsCategory::tryFromName('Missing');   // null
NewsCategory::HotNews->isIn([NewsCategory::HotNews, NewsCategory::RegularNews]); // true

Documentation

The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/enums-for-laravel

Release notes are in CHANGELOG.md. To contribute, see the contributing guide.

Support our work

This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.

Donate to Roundly open source Become a patron on Patreon Donate crypto: BTC, ETH, BNB or SOL

License

The MIT License (MIT). Please see LICENSE for more information.