1
1
![ Enum Helper-Dark] ( branding/laravel-dark.png#gh-dark-mode-only ) ![ Enum Helper-Light] ( branding/laravel-light.png#gh-light-mode-only )
2
2
# Enum Helper
3
3
[ ![ Latest Version on Packagist] ( https://img.shields.io/packagist/v/datomatic/laravel-enum-helper.svg?style=for-the-badge )] ( https://packagist.org/packages/datomatic/laravel-enum-helper )
4
- [](https://github.com/datomatic/laravel-enum-helper/tree/main/tests)
4
+ [](https://github.com/datomatic/laravel-enum-helper/tree/main/tests)
5
5
[](https://github.com/datomatic/laravel-enum-helper/actions/workflows/run-tests.yml)
6
6
[ ![ GitHub Code Style Action Status] ( https://img.shields.io/github/workflow/status/datomatic/laravel-enum-helper/Check%20&%20fix%20styling?label=code%20style&color=5FE8B3&style=for-the-badge )] ( https://github.com/datomatic/laravel-enum-helper/actions/workflows/php-cs-fixer.yml )
7
7
[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/datomatic/laravel-enum-helper.svg?style=for-the-badge )] ( https://packagist.org/packages/datomatic/laravel-enum-helper )
@@ -53,6 +53,28 @@ You can use this functionality simply using the `LaravelEnum` trait.
53
53
``` php
54
54
use Datomatic\LaravelEnumHelper\LaravelEnum;
55
55
56
+ // Pure enum
57
+ enum Status
58
+ {
59
+ use LaravelEnum;
60
+
61
+ case PENDING;
62
+ case ACCEPTED;
63
+ case DISCARDED;
64
+ case NO_RESPONSE;
65
+
66
+ public function color(): string
67
+ {
68
+ return match ($this) {
69
+ self::PENDING => '#000000',
70
+ self::ACCEPTED => '#0000FF',
71
+ self::DISCARDED => '#FF0000',
72
+ self::NO_RESPONSE => '#FFFFFF',
73
+ };
74
+ }
75
+ }
76
+
77
+ // BackedEnum
56
78
enum StatusString
57
79
{
58
80
use LaravelEnum;
@@ -65,12 +87,7 @@ enum StatusString
65
87
// or public function color(?string $lang = null): string
66
88
public function color(): string
67
89
{
68
- return match ($this) {
69
- self::PENDING => '#000000',
70
- self::ACCEPTED => '#0000FF',
71
- self::DISCARDED => '#FF0000',
72
- self::NO_RESPONSE => '#FFFFFF',
73
- };
90
+ ...
74
91
}
75
92
```
76
93
After that you can define a custom "property" method like ` color() ` or ` color(?string $lang = null) ` or define the translations instead.
0 commit comments