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.
Download splitstack/laravel-enum-friendly
More information about splitstack/laravel-enum-friendly
Files in splitstack/laravel-enum-friendly
Package laravel-enum-friendly
Short Description Make your Laravel enums friendly with TypeScript, selects, and many more convenient features
License MIT
Informations about the package laravel-enum-friendly
EnumFriendly
Introduction
EnumFriendly is a powerful PHP package that enhances your Laravel application's enum experience. It provides a friendly interface for working with enums, making them more versatile and easier to integrate with TypeScript, forms, translations, and more.
With EnumFriendly, you can:
- Generate enum classes with a simple artisan command
- Convert enum values to TypeScript types
- Create form-friendly select options
- Generate validation rules automatically
- Access readable labels and collections
- And much more!
Installation
You can install the package via composer:
The package will automatically register its service provider.
Usage
Creating a Friendly Enum
You can use the MakeFriendlyEnum
command to create a new friendly enum:
Example:
This will create an enum Status
with the following cases and the ExtendedEnum
trait:
Using the ExtendedEnum Trait
The ExtendedEnum
trait provides additional methods for your enums (string-backed, int-backed, or plain):
Available Methods
Method | Description | Example Output |
---|---|---|
values() |
Get the enum values | ['active', 'inactive'] |
collect() |
Get the enum values as a collection | Collection of ['active', 'inactive'] |
implode(string $glue = ',') |
Implode the enum values | 'active,inactive' |
toSelectOptions() |
Get the enum values as select options | [['value' => 'active', 'label' => 'Active'], ...] |
keys() |
Get the enum keys | ['ACTIVE', 'INACTIVE'] |
readable() |
Get the enum keys in a readable format | ['Active', 'Inactive'] |
random() |
Get a random enum value | 'active' or 'inactive' |
toTypeScript() |
Make the enum friendly for TypeScript | ['type' => 'Status', 'values' => [...]] |
rules(array $extra = []) |
Make the enum friendly for validation | ['required', 'string', 'in:active,inactive'] |
TypeScript Integration
The toTypeScript()
method generates TypeScript-friendly type definitions:
Form Integration
Create select options for your forms easily:
Validation Rules
Generate Laravel validation rules automatically:
Testing
Run the test suite:
Generate test coverage report:
Contributing
Contributions are welcome! Feel free to:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
The MIT License (MIT). Please see License File for more information.
Credits
- EmilienKopp
- All Contributors
All versions of laravel-enum-friendly with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/console Version ^9.0|^10.0|^11.0|^12.0