Skip to content

Conversation

@erik-perri
Copy link
Contributor

When using the Rule::email helper, if you validate a non-string you end up with the class name as the validation message since no messages get set in the rule. I did see the test was expecting that, but without a mention in the docs of needing Email::class => '...', in your validation file to use the helper I assumed it was unintentional (or there used to be something converting the class string that was lost).

Since the email validator it falls back to will fail on a non-string anyway I removed the check and let it get replaced with the invalid validation message.

% composer create-project laravel/laravel test-app % cd test-app/ % php artisan tinker > Validator::make(['email_address' => 'test@example.com'], ['email_address' => \Illuminate\Validation\Rule::email()])->errors()->toArray() = [] > Validator::make(['email_address' => 'not-an-email'], ['email_address' => \Illuminate\Validation\Rule::email()])->errors()->toArray() = [ "email_address" => [ "The email address field must be a valid email address.", ], ] > Validator::make(['email_address' => 123], ['email_address' => \Illuminate\Validation\Rule::email()])->errors()->toArray() = [ "email_address" => [ "Illuminate\Validation\Rules\Email", ], ] > Validator::make(['email_address' => ['not-a-string']], ['email_address' => \Illuminate\Validation\Rule::email()])->errors()->toArray() = [ "email_address" => [ "Illuminate\Validation\Rules\Email", ], ] 
@taylorotwell taylorotwell merged commit 95fc3d0 into laravel:12.x Oct 9, 2025
66 checks passed
@erik-perri erik-perri deleted the fix-email-rule-helper branch October 9, 2025 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants