Skip to content

[7.x] validate email with custom class#33835

Merged
taylorotwell merged 2 commits intolaravel:7.xfrom
Gummibeer:ft-validate-email-with-custom-class
Aug 12, 2020
Merged

[7.x] validate email with custom class#33835
taylorotwell merged 2 commits intolaravel:7.xfrom
Gummibeer:ft-validate-email-with-custom-class

Conversation

@Gummibeer
Copy link
Contributor

The underlying egulias/email-validator package allows to add custom validators by implementing the Egulias\EmailValidator\Validation\EmailValidation interface.
But right now it's not possible to use the existing email rule to call these custom validators.

This PR allows to pass in a FQCN which is resolved by the container and returned.

use App\Validation\Email\MyCustomValidator;

Validator::make(
  ['email' => 'foo@bar.de'], 
  ['email' => 'email:rfc,dns,'.MyCustomValidator::class]
)->passes();

This example will call the rfc and dns validator like before but also call MyCustomValidator.
That's useful if you want to limit registration to a given email domain, filter trashmails or whatever you want to add on top.

@Gummibeer Gummibeer changed the title validate email with custom class [7.x] validate email with custom class Aug 12, 2020
@taylorotwell taylorotwell merged commit 3da489c into laravel:7.x Aug 12, 2020
@Gummibeer Gummibeer deleted the ft-validate-email-with-custom-class branch August 12, 2020 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants