[9.x] Fix array to string conversion when using custom validation messages for size rules #40074
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR is a follow up on #36885. I've tried ealier this year, but i think i haven't described correctly the issues or used wrong examples and it was rejected, so i'll try it again. When using custom validation messages for size rules, if you define your custom validation messages in `resources/lang/en/validation.php, then laravel thrown an exception when accessing those messages:
This exception comes from the following line, while replacing the
:message
:framework/src/Illuminate/Support/MessageBag.php
Line 268 in 96d2b48
I'm sending this to master because if some user currently uses the custom validation messages, then the response he gets when using
$validator->errors()
is the following:and this PR changes it to:
So, this changes the way you access validation errors from
$validator->errors()->toArray()['file'][0]['string']
to$validator->errors()->toArray()['file'][0]
or$validator->errors()->first('file)
, which is a breaking change.Steps to reproduce
resources/lang/en/validation.php
:web.php
to test the validation message:localhost:8000/test