diff --git a/src/Illuminate/Support/MessageBag.php b/src/Illuminate/Support/MessageBag.php index 835870f65a53..6a49c5692624 100755 --- a/src/Illuminate/Support/MessageBag.php +++ b/src/Illuminate/Support/MessageBag.php @@ -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(); } /**