0
votes

Laravel 8 makes it possible to create custom Validation rules: https://laravel.com/docs/8.x/validation#custom-validation-rules

php artisan make:rule Euro

But then you have to pass the rule as a object (instead of a string):

new Euro

instead of the regular string notation

'required|euro'

Is there anyway to "register" the new Rule classes to a string identifier and use them like you can you the pre-existing rules?

1
you know that it would not change a thing (just make it slower) to achieve this. The string will be used to initiate the rule class and then used.N69S

1 Answers

1
votes

You can use the extend function on the validator. Probably something like:

Validator::extend('euro', new Euro());

This code should be in your AppServiceProvider.