From aac250785866996ec60762de1f84e77853942737 Mon Sep 17 00:00:00 2001 From: Jason Lewis Date: Fri, 2 Mar 2012 18:04:57 +1100 Subject: [PATCH] When no key is provided to first it returns the first message from all the messages. --- laravel/messages.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/laravel/messages.php b/laravel/messages.php index f0c449fd..583a6e44 100644 --- a/laravel/messages.php +++ b/laravel/messages.php @@ -64,6 +64,9 @@ public function has($key) * Get the first message from the container for a given key. * * + * // Echo the first message out of all messages. + * echo $messages->first(); + * * // Echo the first message for the e-mail attribute * echo $messages->first('email'); * @@ -75,9 +78,11 @@ public function has($key) * @param string $format * @return string */ - public function first($key, $format = ':message') + public function first($key = null, $format = ':message') { - return (count($messages = $this->get($key, $format)) > 0) ? $messages[0] : ''; + $messages = is_null($key) ? $this->all($format) : $this->get($key, $format); + + return (count($messages) > 0) ? $messages[0] : ''; } /**