Skip to content

Commit c522e29

Browse files
author
Kevin Buchholz
committed
update readme
1 parent 4fcf66f commit c522e29

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ UserType::values(); // Returns [0, 1, 2, 3]
107107
Returns the key for the given enum value.
108108

109109
``` php
110-
UserType::Modelerator()->key(); // Returns 'Moderator'
110+
UserType::Moderator()->key(); // Returns 'Moderator'
111111
```
112112

113113
### value(): mixed
@@ -123,12 +123,12 @@ UserType::Moderator()->value(); // Returns 1
123123
Returns the localized version of the value, default path is `enums.<EnumClass>.<EnumValue>`, path can be overridden by setting `protected static $localizationPath`.
124124

125125
``` php
126-
UserType::SuperAdministrator()->localized(); // Returns for example 'Super Administrator', but `enums.UserType.3` when not set.
126+
UserType::SuperAdministrator()->localized(); // Returns for example 'Super Administrator', but `enums.App\Enums\UserType.3` when not set.
127127
```
128128

129129
### static randomMember(): static
130130

131-
Returns a random key from the enum. Useful for factories.
131+
Returns a random member from the enum. Useful for factories.
132132

133133
``` php
134134
UserType::randomMember(); // Returns Administrator(), Moderator(), Subscriber() or SuperAdministrator()
@@ -167,7 +167,10 @@ You may validate that an enum value passed to a controller is a valid value for
167167
public function store(Request $request)
168168
{
169169
$this->validate($request, [
170-
'user_type' => ['required', UserType::makeRule()], // Allows all enumeration values
170+
'user_type' => [
171+
'required',
172+
UserType::makeRule(), // Allows all enumeration values
173+
],
171174
]);
172175
}
173176
```
@@ -176,7 +179,10 @@ public function store(Request $request)
176179
public function store(Request $request)
177180
{
178181
$this->validate($request, [
179-
'user_type' => ['required', UserType::makeRuleWithWhitelist([UserType::Moderator(), UserType::Subscriber()])], // allows only the values `1` and `2`
182+
'user_type' => [
183+
'required',
184+
UserType::makeRuleWithWhitelist([UserType::Moderator(), UserType::Subscriber()]), // allows only the values `1` and `2`
185+
],
180186
]);
181187
}
182188
```
@@ -185,16 +191,19 @@ public function store(Request $request)
185191
public function store(Request $request)
186192
{
187193
$this->validate($request, [
188-
'user_type' => ['required', UserType::makeRuleWithBlacklist([UserType::SuperAdministrator(), UserType::Administrator()])], // allows all values but the values `0` and `3`
194+
'user_type' => [
195+
'required',
196+
UserType::makeRuleWithBlacklist([UserType::SuperAdministrator(), UserType::Administrator()]), // allows all values but the values `0` and `3`
197+
],
189198
]);
190199
}
191200
```
192201

193202
## Localization
194203

195-
You can translate the strings returned by the `getDescription` method using Laravel's built in [localization](https://laravel.com/docs/5.6/localization) features.
204+
You can translate the strings returned by the `localized` methods using Laravel's built in [localization](https://laravel.com/docs/5.6/localization) features.
196205

197-
Add a new `enums.php` keys file for each of your supported languages. In this example there is one for English and one for Spanish.
206+
Add a new `enums.php` keys file for each of your supported languages. In this example there is one for English and one for Danish.
198207

199208
```php
200209
// resources/lang/en/enums.php
@@ -205,24 +214,22 @@ use App\Enums\UserType;
205214
return [
206215

207216
UserType::class => [
208-
UserType::Administrator => 'Administrator',
209-
UserType::SuperAdministrator => 'Super administrator',
217+
UserType::Moderator => 'Moderator',
210218
],
211219

212220
];
213221
```
214222

215223
```php
216-
// resources/lang/es/enums.php
224+
// resources/lang/da/enums.php
217225
<?php
218226

219227
use App\Enums\UserType;
220228

221229
return [
222230

223231
UserType::class => [
224-
UserType::Administrator => 'Administrador',
225-
UserType::SuperAdministrator => 'Súper administrador',
232+
UserType::Moderator => 'studievært',
226233
],
227234

228235
];

0 commit comments

Comments
 (0)