Skip to content

Commit

Permalink
add addIf method to message bag
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 29, 2020
1 parent 076c979 commit 50efe09
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Support/MessageBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ public function add($key, $message)
return $this;
}

/**
* Add a message to the message bag if the given conditional is "true".
*
* @param bool $boolean
* @param string $key
* @param string $message
* @return $this
*/
public function addIf($boolean, $key, $message)
{
return $boolean ? $this->add($key, $message) : $this;

This comment has been minimized.

Copy link
@amaelftah

amaelftah Jun 2, 2020

Contributor

@taylorotwell

can't we use value() to allow Closure

return value($boolean) ? $this->add($key,  $message) : $this;
}

/**
* Determine if a key and message combination already exists.
*
Expand Down

0 comments on commit 50efe09

Please sign in to comment.