Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Early return when message format is the default #43149

Merged
merged 1 commit into from
Jul 12, 2022

Conversation

erikn69
Copy link
Contributor

@erikn69 erikn69 commented Jul 12, 2022

Avoid going through all the arrays and replacing the strings with the same when the format is the default :message

After 1e02bc - "summarization" feature all method is always called when validator fails

-parent::__construct('The given data was invalid.');
+parent::__construct(static::summarize($validator));

protected function transform($messages, $format, $messageKey)
{
return collect((array) $messages)
->map(function ($message) use ($format, $messageKey) {
// We will simply spin through the given messages and transform each one
// replacing the :message place holder with the real message allowing
// the messages to be easily formatted to each developer's desires.
return str_replace([':message', ':key'], [$message, $messageKey], $format);
})->all();

@taylorotwell taylorotwell merged commit 7756096 into laravel:9.x Jul 12, 2022
@erikn69 erikn69 deleted the patch-2 branch July 12, 2022 21:15
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