anteris-dev / laravel-rules
Strongly typed Laravel validation attributes.
dev-master
2021-09-16 19:10 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^v8.42.1
- illuminate/validation: ^v8.42.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^9.0
- vimeo/psalm: ^4.0
This package is auto-updated.
Last update: 2024-12-17 03:09:44 UTC
README
This package adds classes that strongly type the Laravel Validation Rules. Currently these classes cannot be used with the default Laravel Validator, though that is our long-term goal.
Using an Attribute
Any of these validation rules may be used as an attribute on a class. If the validation rule accepts parameters, they will be type hinted on the class construct.
class SomeClass { #[Max(255)] public string $firstName; }
Retrieving the Compiled Rules
To retrieve the rule in Laravel format, call the getRules()
method on any of the classes.
For example:
$rule = new Max(255); // Returns: ['max:255'] $array = $rule->getRules();