Skip to content

Commit

Permalink
[5.4] Simplify method (#18184)
Browse files Browse the repository at this point in the history
* Simplify method

* Update MessageBag.php

* Update MessageBag.php

* Update MessageBag.php
  • Loading branch information
jerguslejko authored and taylorotwell committed Mar 2, 2017
1 parent 0fab199 commit 713a2b6
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/Illuminate/Support/MessageBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,13 @@ public function unique($format = null)
*/
protected function transform($messages, $format, $messageKey)
{
$messages = (array) $messages;

// 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.
$replace = [':message', ':key'];

foreach ($messages as &$message) {
$message = str_replace($replace, [$message, $messageKey], $format);
}

return $messages;
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();
}

/**
Expand Down

0 comments on commit 713a2b6

Please sign in to comment.