Skip to content

Commit

Permalink
[8.x] Add Stringable::whenNotEmpty() (laravel#37080)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer authored and bert-w committed Apr 29, 2021
1 parent 4f816bd commit 05ec613
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Illuminate/Support/Stringable.php
Expand Up @@ -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.
*
Expand Down

0 comments on commit 05ec613

Please sign in to comment.