Skip to content

Commit 713a2b6

Browse files
jerguslejkotaylorotwell
authored andcommitted
[5.4] Simplify method (#18184)
* Simplify method * Update MessageBag.php * Update MessageBag.php * Update MessageBag.php
1 parent 0fab199 commit 713a2b6

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/Illuminate/Support/MessageBag.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,13 @@ public function unique($format = null)
236236
*/
237237
protected function transform($messages, $format, $messageKey)
238238
{
239-
$messages = (array) $messages;
240-
241-
// We will simply spin through the given messages and transform each one
242-
// replacing the :message place holder with the real message allowing
243-
// the messages to be easily formatted to each developer's desires.
244-
$replace = [':message', ':key'];
245-
246-
foreach ($messages as &$message) {
247-
$message = str_replace($replace, [$message, $messageKey], $format);
248-
}
249-
250-
return $messages;
239+
return collect((array) $messages)
240+
->map(function ($message) use ($format, $messageKey) {
241+
// We will simply spin through the given messages and transform each one
242+
// replacing the :message place holder with the real message allowing
243+
// the messages to be easily formatted to each developer's desires.
244+
return str_replace([':message', ':key'], [$message, $messageKey], $format);
245+
})->all();
251246
}
252247

253248
/**

0 commit comments

Comments
 (0)