Download the PHP package dilovanmatini/laravel-enumable without Composer
On this page you can find all versions of the php package dilovanmatini/laravel-enumable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download dilovanmatini/laravel-enumable
More information about dilovanmatini/laravel-enumable
Files in dilovanmatini/laravel-enumable
Download dilovanmatini/laravel-enumable
More information about dilovanmatini/laravel-enumable
Files in dilovanmatini/laravel-enumable
Vendor dilovanmatini
Package laravel-enumable
Short Description The Laravel Enumable trait provides a set of utility methods to enhance PHP enums. It includes methods for manipulating enum cases, retrieving labels, and converting enums to various formats.
License MIT
Homepage https://github.com/dilovanmatini/laravel-enumable
Package laravel-enumable
Short Description The Laravel Enumable trait provides a set of utility methods to enhance PHP enums. It includes methods for manipulating enum cases, retrieving labels, and converting enums to various formats.
License MIT
Homepage https://github.com/dilovanmatini/laravel-enumable
Please rate this library. Is it a good library?
Informations about the package laravel-enumable
Enumable Trait for Laravel
Overview
The Laravel Enumable
trait provides a set of utility methods to enhance PHP enums in Laravel. It includes methods for manipulating enum cases, retrieving labels, and converting enums to various formats.
Installation
To install the Laravel Enumable
trait, add it to your project via Composer:
Requirements
- PHP 8.1 or higher
- Laravel 10.0 or higher
Usage
Include the Enumable
trait in your enum classes:
Methods
Class Methods
values()
: Returns an array of all enum values.names()
: Returns an array of all enum names.labels()
: Converts the enum to an associative array with values as keys and labels as values.getCase(string $value)
: Returns the enum case for the given value.getName(string $value)
: Returns the name of the enum case for the given value.getLabel(string $value)
: Returns the label of the enum case for the given value.toArray()
: Converts the enum to an associative array with values as keys and names as values.toCollection()
: Converts the enum to a Laravel collection.toSelectArray()
: Alias for toLabelsArray().exists(object|string $value)
: Checks if the given value exists in the enum.random()
: Returns a random enum case.default()
: Returns the default enum case.first()
: Returns the first enum case.last()
: Returns the last enum case.count()
: Returns the number of enum cases.only(array $cases)
: Returns a new object with only the specified cases.except(array $cases)
: Returns a new object with all cases except the specified ones.generate(array $cases)
: Generates a new object with the given cases.
Instance (Object) Methods
label()
: Returns the label of the enum case.headline()
: Returns the headline of the enum case.str(bool $label = false)
: Returns a new object to apply Laravel string helper methods.
Examples
Custom Labels
Override the setLabels
method in your enum class to provide custom labels:
License
This package is open-sourced software licensed under the MIT license.
All versions of laravel-enumable with dependencies
PHP Build Version
Package Version
The package dilovanmatini/laravel-enumable contains the following files
Loading the files please wait ....