Download the PHP package iteks/laravel-enum without Composer

On this page you can find all versions of the php package iteks/laravel-enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-enum

Laravel ENUM

Total Downloads Latest Stable Version License

The Laravel Enum package enriches Laravel's enum support, integrating advanced features like attribute handling, select array transformation, and facade access for streamlined enum operations. Designed for Laravel applications, it offers a suite of utilities for both backed enums and attribute-enhanced enums, including descriptive annotations, ID management, label generation, and metadata association. This package streamlines working with enums in Laravel by providing intuitive, fluent interfaces for common tasks, enhancing enum usability in forms, API responses, and more. Whether you're defining select options, querying enum attributes, or integrating enums tightly with Laravel features, Laravel Enum simplifies these processes, making enum management in Laravel applications both powerful and efficient. Offered by iteks, Developed by jeramyhing.

Get Started

Requires PHP 8.1+

Install Laravel Enum via the Composer package manager:

Usage

ExampleBackedEnum class

The Laravel Enum methods are designed for PHP 8 Backed Enumeration classes.

Laravel Enum helper and trait methods extend an existing backed enum class for more versatile enum handling. Additionally, Laravel Enum offers a fluent way to add and manage PHP 8 Attributes on backed enum cases. This package comes with four available attributes to readily assign to your enum cases: Description, Id, Label, and Metadata. The ExampleBackedEnum class below demonstrates how you can apply these attributes to you enums. You may pick and choose which attributes you wish to take advantage of.

top

Attributes

The package provides four attributes to enhance your enum classes and cases:

Description Attribute

Provides descriptive text for enum classes and cases.

Id Attribute

Provides unique identifiers for enum cases.

Label Attribute

Provides human-readable labels for enum cases.

Metadata Attribute

Provides additional metadata for enum classes and cases. Supports multiple metadata attributes and can be used on both the enum class and its cases.

Attribute Capabilities Summary

top

Enum Helpers (BackedEnum)

First, import the helper class:

Note: This group of helpers does NOT require any trait to be applied to the target enum class. You may immediately use the the following methods:

Enum::asSelectArray()

Get a backed enum class as an array to populate a select element. The array will consist of a text key column containing values of the case name in display format, and a value keys column containing values using the original simpler values.

Note: This method will first check for Label and Id attributes applied to the target enum class. If they are present, the method will prioritize those values. If not present, the method will return a mutated Headline value from the case name.

Enum::toLabel()

Create a label from the case name.

Enum::toLabels()

Create and compile an array of labels from the case names.

top

Enum Helpers (HasAttributes)

First, ensure that the target enum class has the HasAttributes trait applied, as shown in the ExampleBackedEnum class above.

Then, import the helper class:

You may then use the following methods:

Enum::attributes()

Accessing attributes.

Retrieve all attributes for a given case.

Retrieve a subset of the attributes for a given case.

Retrieve all attributes for all cases.

Retrieve a subset of the attributes for all cases.

Enum::description()

Retrieve the description attribute.

Enum::descriptions()

Retrieve the description attribute for all cases.

Enum::id()

Retrieve the id attribute.

Enum::ids()

Retrieve the id attribute for all cases.

Enum::label()

Retrieve the label attribute.

Enum::labels()

Retrieve the label attribute for all cases.

Enum::metadata()

Retrieve the metadata attribute.

Enum::metadatum()

Retrieve the metadata attribute for all cases.

top

Enum Traits (BackedEnum)

First, ensure that the target enum class has the BackedEnum trait applied, as shown in the ExampleBackedEnum class above.

Then, you may then use the following methods:

asSelectArray()

Get a backed enum class as an array to populate a select element. The array will consist of a text key column containing values of the case name in display format, and a value keys column containing values using the original simpler values.

Note: This method will first check for Label and Id attributes applied to the target enum class. If they are present, the method will prioritize those values. If not present, the method will return a mutated Headline value from the case name.

fromName()

Maps a scalar to an enum instance.

name()

Retrieve the case name for the given simpler value.

names()

Retrieve an array containing all of the case names.

toLabel()

Create a label from the case name.

toLabels()

Create and compile an array of labels from the case names.

tryFromName()

Maps a scalar to an enum instance or null.

value()

Retrieve the simpler value for the given case name.

values()

Retrieve an array containing all of the simpler values.

top

Enum Traits (HasAttributes)

First, ensure that the target enum class has the HasAttributes trait applied, as shown in the ExampleBackedEnum class above.

Then, you may then use the following methods:

attributes()

Retrieve the attributes for a given case.

Retrieve a subset of the attributes for a given case.

Retrieve the attributes for all cases.

Retrieve a subset of the attributes for all cases/

description()

Retrieve the description attribute.

descriptions()

Retrieve the description attribute for all cases.

id()

Retrieve the id attribute.

ids()

Retrieve the id attribute for all cases.

label()

Retrieve the label attribute.

labels()

Retrieve the label attribute for all cases.

metadata()

Retrieve the metadata attribute.

metadatum()

Retrieve the metadata attribute for all cases.

top

String Helper Macros

These helperas are booted when installing the package and are immediately available for use.

Str::splitConstantCase()

Splits a "CONSTANT_CASE" string into words separated by whitespace.

Str::splitEnumCase()

Splits a "EnumCase" string into words separated by whitespace.

top


All versions of laravel-enum with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
laravel/framework Version ^9.46|^10.10|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package iteks/laravel-enum contains the following files

Loading the files please wait ....