Skip to content

Conversation

jackbayliss
Copy link
Contributor

@jackbayliss jackbayliss commented Oct 12, 2025

Currently for the the Enum validation rule Can and anyOf to do a custom validation message you need use the fully qualified class name, ie:

 'school.Illuminate\Validation\Rules\Enum' => 'Please enter valid school'

This PR makes it so you can do the short (normal?) string version ie:

 'school.enum' => 'Please enter valid school'

Which is inline with other rules - such as:

    'forename.required' => 'Forename is required',
    'surname.required' => 'Surname is required',
    'school.enum'=> 'Please select a valid school',

I've added tests for all affected rules to prove it works for both the fqcn and short hand which should help prevent regression.

I don't believe this is a breaking change- which is why I did it this way - can target 13.x - open to feedback!

Thanks

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@jackbayliss jackbayliss marked this pull request as ready for review October 12, 2025 14:55
@jackbayliss jackbayliss changed the title [12.x] Ensure custom validation messages work for Enum and AnyOf [12.x] Ensure custom validation messages work for AnyOf, Can and Enum Oct 13, 2025
@taylorotwell taylorotwell merged commit 1f0025f into laravel:12.x Oct 14, 2025
66 checks passed
@jackbayliss jackbayliss deleted the enum-fix branch October 14, 2025 23:02
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.

2 participants