roundly-consulting/enums-for-laravel

Convenient helper methods for PHP enums in Laravel applications
1,106
Install
composer require roundly-consulting/enums-for-laravel
Latest Version:1.0.1
PHP:^8.4
License:MIT
Last Updated:Oct 5, 2026
Links: GitHub  ·  Packagist
Maintainer: mihaliak

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.

License

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

Related Packages

hasanhawary/lookup-manager

Clean Laravel lookup manager: fetch model lookups and enum lists (app and module...

1,185 3
ronasit/laravel-helpers

Provided helpers function and some helper class.

90,389 20
kun391/laravel-helpers

Laravel Helpers for Non-Laravel Projects

6,469 2
laravel-enso/helpers

Helper classes dependency for Laravel Enso

105,373 8
rappasoft/laravel-helpers

Laravel Helpers for Non-Laravel Projects

708,066 277

Version History

Version Released PHP Laravel License
1.0.1 ^8.4 ^12.0|^13.0 MIT
1.0.0 ^8.4 ^12.0|^13.0 MIT