Download the PHP package splitstack/laravel-enum-friendly without Composer

On this page you can find all versions of the php package splitstack/laravel-enum-friendly. 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-friendly

EnumFriendly for Laravel

Tests

PHP Version Laravel Version Total Downloads

Introduction

EnumFriendly for Laravel is a powerful PHP package that enhances your Laravel application's enum experience. Built on top of the dependency-free EnumFriendly Core, it provides Laravel-specific features like Collections, validation rules, and Artisan commands while maintaining all the core functionality.

🚀 Key Features:

With EnumFriendly for Laravel, you can:

Installation

You can install the package via composer:

The package will automatically register its service provider and install the dependency-free core package.

Laravel-Specific Features

Artisan Commands

Generate enum classes with the MakeFriendlyEnum command:

Example:

This will create an enum Status with the following cases and the ExtendedEnum trait:

Laravel Collections Integration

The Laravel package extends several core methods to return Laravel Collections instead of arrays:

Laravel Validation Rules

Generate Laravel validation rules automatically:

Usage

Adding the ExtendedEnum Trait

Simply add the ExtendedEnum trait to your existing enums to unlock all the enhanced functionality:

Available Methods

The ExtendedEnum trait provides all core functionality plus Laravel-specific enhancements:

Core Methods (inherited from EnumFriendly Core)

Method Description Example Output
values() Get all enum values (or names for unbacked) ['active', 'inactive']
keys() Get all enum case names ['ACTIVE', 'INACTIVE']
readable() Get case names in human-readable format ['Active', 'Inactive']
implode(string $glue = ',') Implode the enum values 'active,inactive'
toOptionsArray() Get enum as form select options array [['value' => 'active', 'label' => 'Active'], ...]
toReadableArray() Get enum as value => readable label mapping ['active' => 'Active', 'inactive' => 'Inactive']
toArray() Get enum as value => case name mapping ['active' => 'ACTIVE', 'inactive' => 'INACTIVE']
toJsonArray() Get enum as case name => value mapping ['ACTIVE' => 'active', 'INACTIVE' => 'inactive']
random() Get a random enum value 'active' or 'inactive'
randomCase() Get a random enum case instance MyEnum::ACTIVE or MyEnum::INACTIVE
coerceEnum($value) Safely convert value to enum instance MyEnum::ACTIVE or null
coerceValue($value) Safely convert value to enum value 'active' or null
hasValue($value) Check if value exists in enum true or false
only($cases) Filter enum cases by names [MyEnum::ACTIVE]
onlyValues($values) Filter enum values by values ['active', 'pending']
except($cases) Exclude enum cases by names [MyEnum::INACTIVE]
exceptValues($values) Exclude enum values by values ['pending', 'completed']
count() Get total number of enum cases 2
isBacked() Check if enum is backed true or false
toTypeScript() Make enum TypeScript-friendly ['type' => 'MyEnum', 'values' => [...]]
comment($prefix) Generate descriptive comment 'possible values: active, inactive'
toJson($options) Convert to JSON string '{"active":"ACTIVE","inactive":"INACTIVE"}'
fromValueOr($value, $default) Get enum with fallback MyEnum::ACTIVE or $default
label() Get human-readable label for instance 'Active' (when called on enum instance)
description() Get description if implemented Custom description or null
is($value) Compare enum instance with value true or false
in($values) Check if enum instance is in array true or false

Laravel-Enhanced Methods

Method Description Laravel Enhancement
collect() Get enum values as Laravel Collection Returns Collection instead of array
toSelectOptions() Get enum as select options Returns Collection instead of array
rules(array $extra = []) Generate Laravel validation rules Laravel-specific validation format
rule() Get Laravel Enum validation rule Returns Illuminate\Validation\Rules\Enum

Common Usage Examples

TypeScript Integration

Generate TypeScript-compatible type definitions:

Form Integration

Create select options for your Laravel forms:

Laravel Validation

Safe Value Coercion

Safely convert unknown values to enum instances:

Working with Laravel Collections

Filter and manipulate enum cases using Laravel Collections:

Instance Methods

Use methods directly on enum instances:

Why Choose EnumFriendly for Laravel?

🚀 Built on Solid Foundation

Based on the dependency-free EnumFriendly Core package, ensuring stability and performance.

🔧 Laravel-Optimized

📦 Zero Configuration

🎯 Developer Experience

🔄 Migration Friendly

Easy to integrate into existing Laravel projects:

Testing

Run the test suite:

Generate test coverage report:

Contributing

Contributions are welcome! Feel free to:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

The MIT License (MIT). Please see License File for more information.

Credits

Related Packages


All versions of laravel-enum-friendly with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
splitstack/enum-friendly-core Version *
illuminate/support Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/console Version ^9.0|^10.0|^11.0|^12.0|^13.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 splitstack/laravel-enum-friendly contains the following files

Loading the files please wait ...