From 50efe099b59e75563298deb992017b4cabfb021d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 29 May 2020 11:40:10 -0500 Subject: [PATCH] add addIf method to message bag --- src/Illuminate/Support/MessageBag.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Illuminate/Support/MessageBag.php b/src/Illuminate/Support/MessageBag.php index dec897d4affc..bfc4fd29616d 100755 --- a/src/Illuminate/Support/MessageBag.php +++ b/src/Illuminate/Support/MessageBag.php @@ -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; + } + /** * Determine if a key and message combination already exists. *