New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

roundly-consulting/enums-for-laravel

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

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.

Related Packages

hasanhawary/lookup-manager

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

1,291 3
aurion72/helpers

Aurion72 Helpers

14,667 0
xnxk/helpers

Provides backwards compatibility for helpers in the XNXK Tech.

11,896 0
velcoda/helpers

Your Package Description here

4,997
mossengine/helper

PHP Class that streamlines usages of static method helpers without needing to lo...

1,842 0

Version History

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