Download the PHP package mahmudul/lara-enum without Composer
On this page you can find all versions of the php package mahmudul/lara-enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mahmudul/lara-enum
More information about mahmudul/lara-enum
Files in mahmudul/lara-enum
Package lara-enum
Short Description A lightweight Laravel enum enhancement package with labels, descriptions and helpers.
License MIT
Homepage https://github.com/Pondit-Hasan/lara-enum
Informations about the package lara-enum
Lara Enum
Laravel custom enum utilities that add helpful attributes and helpers to your native PHP 8.1+ enums. Provides:
- A Description attribute you can place on enum cases for human-friendly labels
- A Translatable attribute to localize labels via a translation key (uses Laravel's __() helper)
- A HasEnumAttributes trait that gives you convenient helpers like label(), values(), and asOptions()
Requirements
- PHP: ^8.4
- Illuminate Support: ^12.0 or ^13.0 (works in Laravel applications using these versions)
Installation
Install via Composer:
The package uses Laravel package auto-discovery. No manual provider registration is needed.
Usage
1) Define your enum
Add the Description or Translatable attribute to cases and use the HasEnumAttributes trait to gain helpers.
Using Translatable (for localized labels)
Note: Translatable uses Laravel's __() helper, so ensure your translation keys exist.
Label resolution order
The label() method resolves the display label in the following priority order:
1) Translatable attribute key via __() 2) Description attribute text 3) Humanized enum value (Str::headline)
2) Helpers
-
label(): string
-
values(bool $asArray = false): Collection|array
- asOptions(string $labelKey = 'label', string $valueKey = 'value', bool $asArray = false): Collection|array
These can be fed directly into form selects, API responses, etc.
Laravel Integration
- Auto-discovered service provider: Mahmudul\LaraEnum\LaraEnumServiceProvider
- No configuration is required
Development
- Minimum stability is set to "dev" with prefer-stable to allow framework version ranges.
License
MIT License. See the LICENSE file (or the package metadata) for details.