Merge pull request #379 from jasonlewis/patch-6

Allow no key in $messages->first()
This commit is contained in:
Taylor Otwell 2012-03-04 11:59:00 -08:00
commit 9ab1144f78
1 changed files with 7 additions and 2 deletions

View File

@ -64,6 +64,9 @@ public function has($key)
* Get the first message from the container for a given key. * Get the first message from the container for a given key.
* *
* <code> * <code>
* // Echo the first message out of all messages.
* echo $messages->first();
*
* // Echo the first message for the e-mail attribute * // Echo the first message for the e-mail attribute
* echo $messages->first('email'); * echo $messages->first('email');
* *
@ -75,9 +78,11 @@ public function has($key)
* @param string $format * @param string $format
* @return string * @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] : '';
} }
/** /**