Browse Source

When no key is provided to first it returns the first message from all the messages.

Jason Lewis 12 years ago
parent
commit
aac2507858
1 changed files with 7 additions and 2 deletions
  1. 7 2
      laravel/messages.php

+ 7 - 2
laravel/messages.php

@@ -64,6 +64,9 @@ class Messages {
 	 * Get the first message from the container for a given key.
 	 *
 	 * <code>
+	 *		// 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 @@ class Messages {
 	 * @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] : '';
 	}
 
 	/**