You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returns the localized version of the value, default path is `enums.<EnumClass>.<EnumValue>`, path can be overridden by setting `protected static $localizationPath`.
124
124
125
125
```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.
127
127
```
128
128
129
129
### static randomMember(): static
130
130
131
-
Returns a random key from the enum. Useful for factories.
131
+
Returns a random member from the enum. Useful for factories.
132
132
133
133
```php
134
134
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
167
167
public function store(Request $request)
168
168
{
169
169
$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
+
],
171
174
]);
172
175
}
173
176
```
@@ -176,7 +179,10 @@ public function store(Request $request)
176
179
public function store(Request $request)
177
180
{
178
181
$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
+
],
180
186
]);
181
187
}
182
188
```
@@ -185,16 +191,19 @@ public function store(Request $request)
185
191
public function store(Request $request)
186
192
{
187
193
$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
+
],
189
198
]);
190
199
}
191
200
```
192
201
193
202
## Localization
194
203
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.
196
205
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.
0 commit comments