anteris-dev/laravel-rules

Strongly typed Laravel validation attributes.

dev-master 2021-09-16 19:10 UTC

This package is auto-updated.

Last update: 2024-10-17 02:47:51 UTC


README

Tests Style

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();