Download the PHP package geekk-net/laravel-enum without Composer
On this page you can find all versions of the php package geekk-net/laravel-enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download geekk-net/laravel-enum
More information about geekk-net/laravel-enum
Files in geekk-net/laravel-enum
Package laravel-enum
Short Description Elegant Enum implementation for Laravel. With make:enum command, ability to casting for Eloquent models and labels translations via lang files.
License MIT
Homepage https://github.com/geekk-net/laravel-enum
Informations about the package laravel-enum
Elegant Enum implementation for Laravel
This package is fork of removed one https://github.com/mad-web/laravel-enum.git
This package is not supported. Please switch to php enum.
Based on MyCLabs PHP Enum and implements SplEnum interface.
You could find documentation for base features in PHP Enum Readme.
Features:
make:enum
command- ability to cast enum fields for Eloquent models
- labels translation via lang files
- simple validation rule
Simple Enum Example
Installation
For Laravel < 7 version - use 1.0 branch.
You can install the package via composer:
Usage
Make new Enum class via artisan command:
to populate Enum with your own values, pass it after name
argument:
Create instance of Enum class
Enums support native Custom Casts feature out of the box.
Specify Enum class for attribute in $casts
array:
after that you could get and set enum field using enum classes
Enum values labels (Localization)
Create enums.php
lang file and declare labels for enum values
and get a label
To override default enum lang file path, publish laravel-enum
config
and change lang_file_path
option
Validation Rule
You may validate an enum value from a request by using the EnumRule
class or Enum::rule()
method.
If you want to validate an enum key instead of an enum value you can by specifying you want to validate against the key instead of the value.
To customize validation message, add enum
key to validation lang file
Additional methods
getRandomKey(): string
Returns a random key from the enum.
getRandomValue()
Returns a random value from the enum.
label(): string
Returns label for the enum value object
labels(): array
Returns all labels for a enum
is($value): bool
Checks whether the current enum value is equal to a given enum
rule(): EnumRule
Returns instance of validation rule class for the Enum
getConstList(bool $include_default = false): array
Returns all consts (possible values) as an array according to SplEnum::getConstList
Changelog
Please see CHANGELOG for more information on what has changed recently.
Testing
Contributing
Please see CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Mad Web
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-enum with dependencies
illuminate/console Version ^7.0 || ^8.0
illuminate/support Version ^7.0 || ^8.0
illuminate/translation Version ^7.0 || ^8.0
myclabs/php-enum Version ^1.7.0