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
| init(>name<,>cast<) |```["name"=> >name<]```|\>name< = instanceof PreferenceGroup | Unique identifier for the preference |
258
+
| init(>name<,>cast<) |```["cast"=> >cast<]```|\>cast< = instanceof CastableEnum | Caster to translate the value between all different scenarios. Currently: Api-calls as well as saving to and retrieving fron the DB |
259
+
| nullable(>nullable<) |```["nullable"=> >nullable<]```|\>nullable< = bool | Whether the default value can be null and if the preference can be set to null |
260
+
| withDefaultValue(>default_value<) |```["default_value"=> >default_value<]```|\>default_value< = mixed, but must comply with the cast & validationRule | Initial value for this preference |
261
+
| withDescription(>description<) |```["description"=> >description<]```|\>description< = string | Legacy code from v1.x has no actual use as of now |
262
+
| withPolicy(>policy<) |```["policy"=> >policy<]```|\>policy< = instanceof PreferencePolicy | Authorize actions such as update/delete etc. on certain preferences. |
263
+
| withRule(>rule<) |```["rule"=> >rule<]```|\>rule< = instanceof ValidationRule | Additional validation Rule, to validate values before setting them |
264
+
| setAllowedClasses(>allowed_values<) |```["allowed_values"=> >allowed_values<]```|\>allowed_values< = array of string classes. For non Primitive Casts only | Current use-cases: <br/> - restrict classes of enum or object that can be set to this preference<br/> - reconstruct the original class when sending data via api. |
265
+
266
+
### Available helper functions
267
+
268
+
Optionally, pass the default value as a second parameter
| AndRule |`new AndRule(new BetweenRule(2.4, 5.5), new LowerThanRule(5))`| Expects `n` ValidationRule, ensures all pass |
413
-
| OrRule |`new OrRule(new BetweenRule(2.4, 5.5), new LowerThanRule(5))`| Expects `n` ValidationRule, ensures at least one passes |
414
-
| BetweenRule |`new BetweenRule(2.4, 5.5)`| For INT and FLOAT, check that the value is between min and max |
415
-
| InRule |`new InRule("it","en","de")`| Expects the value to be validated to be in that equal to one of the `n` params |
416
-
| InstanceOfRule |`new InstanceOfRule(Theme::class)`| For non primitive casts, checks the instance of the value's class to validate. Tip: goes along well with the `OrRule`|
417
-
| IsRule |`new IsRule(Type::ITERABLE)`| Expects a `Matteoc99\LaravelPreference\Enums\Type` Enum. Checks e.g. if the value is iterable |
418
-
| LowerThanRule |`new LowerThanRule(5)`| For INT and FLOAT, check that the value to be validated is less than the one passed in the constructor |
450
+
| OrRule |`new OrRule(new BetweenRule(2.4, 5.5), new LowerThanRule(5))`| Expects `n` ValidationRule, ensures at least one passes |
451
+
| LaravelRule |`new LaravelRule("required\|numeric")`| Expects a string, containing a Laravel Validation Rule |
452
+
| BetweenRule |`new BetweenRule(2.4, 5.5)`| For INT and FLOAT, check that the value is between min and max |
453
+
| InRule |`new InRule("it","en","de")`| Expects the value to be validated to be in that equal to one of the `n` params |
454
+
| InstanceOfRule |`new InstanceOfRule(Theme::class)`| For non primitive casts, checks the instance of the value's class to validate. Tip: goes along well with the `OrRule`|
455
+
| IsRule |`new IsRule(Type::ITERABLE)`| Expects a `Matteoc99\LaravelPreference\Enums\Type` Enum. Checks e.g. if the value is iterable |
456
+
| LowerThanRule |`new LowerThanRule(5)`| For INT and FLOAT, check that the value to be validated is less than the one passed in the constructor |
419
457
420
458
### Custom Rules
421
459
422
-
implement`ValidationRule`
460
+
Implement Laravel's`ValidationRule`
423
461
424
462
#### Example:
425
463
@@ -453,11 +491,11 @@ class MyRule implements ValidationRule
453
491
454
492
## Policies
455
493
456
-
each preference can have a Policy, should [isUserAuthorized](#isuserauthorized) not be enough for your usecase
494
+
Each preference can have a Policy, should [isUserAuthorized](#isuserauthorized) not be enough for your usecase
457
495
458
496
### Creating policies
459
497
460
-
implement`PreferencePolicy` and the 4 methods defined by the contract
498
+
Implement`PreferencePolicy` and the 4 methods defined by the contract
| init(>name<,>cast<) |```["name"=> >name<]```|\>name< = instanceof PreferenceGroup | Unique identifier for the preference |
488
-
| init(>name<,>cast<) |```["cast"=> >cast<]```|\>cast< = instanceof CastableEnum | Caster to translate the value between all different scenarios. Currently: Api-calls as well as saving to and retrieving fron the DB |
489
-
| nullable(>nullable<) |```["nullable"=> >nullable<]```|\>nullable< = bool | Whether the default value can be null and if the preference can be set to null |
490
-
| withDefaultValue(>default_value<) |```["default_value"=> >default_value<]```|\>default_value< = mixed, but must comply with the cast & validationRule | Initial value for this preference |
491
-
| withDescription(>description<) |```["description"=> >description<]```|\>description< = string | Legacy code from v1.x has no actual use as of now |
492
-
| withPolicy(>policy<) |```["policy"=> >policy<]```|\>policy< = instanceof PreferencePolicy | Authorize actions such as update/delete etc. on certain preferences. |
493
-
| withRule(>rule<) |```["rule"=> >rule<]```|\>rule< = instanceof ValidationRule | Additional validation Rule, to validate values before setting them |
494
-
| setAllowedClasses(>allowed_values<) |```["allowed_values"=> >allowed_values<]```|\>allowed_values< = array of string classes. For non Primitive Casts only | Current use-cases: <br/> - restrict classes of enum or object that can be set to this preference<br/> - reconstruct the original class when sending data via api. |
495
-
496
521
## Routing
497
522
498
-
off by default, enable it in the config
523
+
Off by default, enable it in the config
499
524
500
525
> [!WARNING]
501
526
> **(Current) limitation**: it's not possible to set object casts via API
@@ -505,7 +530,7 @@ off by default, enable it in the config
0 commit comments