Skip to content

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

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
erikn69:patch-2
Jul 12, 2022
Merged

[9.x] Early return when message format is the default#43149
taylorotwell merged 1 commit into
laravel:9.xfrom
erikn69:patch-2

Conversation

@erikn69
Copy link
Copy Markdown
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