diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index 290914bc32a1..700163f165d6 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -744,6 +744,23 @@ public function whenEmpty($callback) return $this; } + /** + * Execute the given callback if the string is not empty. + * + * @param callable $callback + * @return static + */ + public function whenNotEmpty($callback) + { + if ($this->isNotEmpty()) { + $result = $callback($this); + + return is_null($result) ? $this : $result; + } + + return $this; + } + /** * Limit the number of words in a string. *