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

Attributes

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 example enum classes linked below demonstrate how you can apply these attributes to your enums. You may pick and choose which attributes you wish to take advantage of.

To apply an attribute to an enum, be sure to import the BackedEnum and the HasAttributes traits and the attribute class needed.

The package provides the following 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. Metadata can be specified as either an array or a JSON string (must use double quotes for valid JSON).

The metadata values can be accessed in three ways:

  1. Through the meta() accessor (recommended for property-like access)
    • meta()
  2. Using the metadata() method with optional key filtering (recommended for case specific data)
    • Enum::metadata()
    • metadata()
  3. Using the metadatum() method with optional key filtering (recommended for all enum cases within the class)
    • Enum::metadatum()
    • metadatum()

Note: While Id and Label attributes technically support class-level usage, this is deprecated and will be removed in v2.0.0. Please use these attributes only on enum cases.

top

Enum Helpers (BackedEnum)

The Laravel Enum package provides a set of helper methods through the Enum facade to work with backed enums. These methods are available for any enum that uses the BackedEnum trait.

To use the Enum facade, start by importing the Enum helper into the file where your logic will be:

Enum::asSelectArray()

Convert an enum to a select array format, useful for form select elements.

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()

Convert an enum case to its label representation.

Enum::toLabels()

Convert multiple enum cases to their label representations.

top

Enum Helpers (HasAttributes)

The Laravel Enum package provides a rich set of helper methods through the Enum facade to work with enum attributes. These methods are available for any enum that uses both the BackedEnum and HasAttributes traits.

To use the Enum facade, start by importing the Enum helper into the file where your logic will be:

Enum::attributes()

Get all attributes for an enum instance or all class instances.

Filter attributes for the enum instance.

Get all attributes for each instance in the class.

Filter all attributes for each instance in the class by key(s).

Enum::description()

Get the description for an enum case.

Enum::descriptions()

Get descriptions for multiple enum cases.

Use the keyBy argument to get an associative array using the case name or simple value as the keys/indices.

Enum::id()

Get the ID attribute for an enum case.

Enum::ids()

Get IDs for multiple enum cases.

Use the keyBy argument to get an associative array using the case name or simple value as the keys/indices.

Enum::label()

Get the label for an enum case.

Enum::labels()

Get labels for multiple enum cases.

Enum::metadata()

Retrieve the metadata attribute or specific metadata values by key(s).

Get specific metadata value.

Filter metadata by specific keys.

Enum::metadatum()

Retrieve the metadata attribute for all cases, optionally filtered by key.

Get specific metadatum values for the class.

Use the keyBy argument to get an associative array using the case name or simple value as the keys/indices.

Filter metadatum by specific keys.

top

Enum Traits (BackedEnum)

The BackedEnum trait provides instance methods for working with backed enums. Apply this trait to your enum class to access these methods directly on enum instances.

asSelectArray()

Convert the enum to a select array format, useful for form select elements.

fromName()

Create an enum instance from a case name.

name()

Get the case name of an enum instance.

names()

Get all case names from the enum.

toLabel()

Convert an enum instance to its label representation.

toLabels()

Convert multiple enum instances to their label representations.

tryFromName()

Attempt to create an enum instance from a case name, returning null if the name doesn't exist.

value()

Get the backed value of an enum instance.

values()

Get all backed values from the enum.

top

Enum Traits (HasAttributes)

The HasAttributes trait provides instance methods for working with enum attributes. Apply this trait along with BackedEnum to access these methods directly on enum instances.

attributes()

Get all attributes for an enum instance or all class instances.

Filter attributes for the enum instance.

Get all attributes for each instance in the class.

Filter all attributes for each instance in the class by key(s).

description()

Get the description(s) for an enum instance or class.

descriptions()

Get descriptions for all enum cases.

Use the keyBy argument to get an associative array using the case name or simple value as the keys/indices.

id()

Get the ID attribute for an enum instance.

ids()

Get IDs for all enum cases.

Use the keyBy argument to get an associative array using the case name or simple value as the keys/indices.

label()

Get the label for an enum instance.

labels()

Get labels for all enum cases.

metadata()

Retrieve the metadata attribute or specific metadata values by key(s).

Get specific metadata value.

Filter metadata by specific keys.

metadatum()

Retrieve the metadata attribute for all cases, optionally filtered by key.

Get specific metadatum values only for the class.

Use the keyBy argument to get an associative array using the case name or simple value as the keys/indices.

Filter metadatum by specific keys.

meta()

Access metadata values using property-like syntax. This is the recommended way to access individual metadata values.

top

String Helper Macros

The Laravel Enum package extends Laravel's Str facade with additional helper methods for working with enum case names.

Str::splitConstantCase()

Split a constant case string into its constituent words. This is useful when working with enum case names that follow constant case naming conventions (a.k.a. Snake case).

Str::splitEnumCase()

Split an enum case name into its constituent words. This is useful when working with enum case names that follow enum case (a.k.a. Pascal case) naming conventions. Also, handles Camel case strings.

These string helper macros are particularly useful when you need to:

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 ....