Convenient helper methods for PHP enums in Laravel applications
roundly-consulting/enums-for-laravel is a Laravel package for convenient helper methods for php enums in laravel applications.
It currently has 0 GitHub stars and 3.105 downloads on Packagist (latest version 1.1.0).
Install it with composer require roundly-consulting/enums-for-laravel.
Discover more Laravel packages by roundly-consulting
or browse all Laravel packages to compare alternatives.
Last updated
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.
Requires PHP 8.4, Laravel 12 or 13.
composer require roundly-consulting/enums-for-laravel
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
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.
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.
The MIT License (MIT). Please see LICENSE for more information.