Download the PHP package isap-ou/laravel-enum-helpers without Composer
On this page you can find all versions of the php package isap-ou/laravel-enum-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download isap-ou/laravel-enum-helpers
More information about isap-ou/laravel-enum-helpers
Files in isap-ou/laravel-enum-helpers
Package laravel-enum-helpers
Short Description Adding some helpers functions to PHP8 native enums for laravel projects
License MIT
Informations about the package laravel-enum-helpers
Laravel Enum Helpers
This package brings some helpers to native PHP Enums
Installation
You can install the package via composer:
You will most likely need to edit the extensive configuration, so you can publish the config file with:
Default config
enum_locations
- path where enums located. Key is directory with enums, value - namespace for specified directorypost_migrate
- enable or disable post migrate event listenerjs_objects_file
- path for generated js outputlabel.prefix
- get default prefix for translations of enum fieldslabel.namespace
- get default prefix for translations of enum namespace (when using as part of own package)
Available helpers
Migration helper
The way easy to add all enums to database column.
Just add to Enum trait InteractWithCollection
And in migration class
Update enum columns in DB
Artisan command allows update available(possible) values for specific enum column.
Modify enum:
And run command
There is also a listener enabled by default that will run after a successful migration.
To disable it edit enum-helpers.php
:
Convert PHP Enums to JS objects
Artisan command allows generate js objects based on enums
Modify enum:
And run command
Output will
You can specify output path in config enum-helpers.php
Label helper
Label helper allows to transform an enum instance into a textual label. This is useful for displaying human-readable translatable enum values in your UI.
and get textual label
By default it will try to find translation with key e.g. ExampleEnum.ENUM_ONE
ExampleEnum
- class nameENUM_ONE
- enum item name
Method getLabel
has two optional parameters:
prefix
- Allows prepend prefix for translation keynamespace
- Allows to prepend namespace. Suitable during own package development
There is possibility to define prefix
and namespace
globally via enum-helpers.config
or on enum level via methods
Optional. Can be added interface
\IsapOu\EnumHelpers\Contracts\HasLabel
that can solve ide autocomplete and tips
This helper compatible with Enums in FilamentPHP
Contributing
Please, submit bugs or feature requests via the Github issues.
Pull requests are welcomed!
Thanks!
License
The AgileCRM Client for Laravel is open-sourced software licensed under the MIT license