diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 30dfb411107f..dfadbb605164 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -687,6 +687,28 @@ public static function isUlid($value) return Ulid::isValid($value); } + /** + * Determine if the given string is empty. + * + * @param string $value + * @return bool + */ + public static function isEmpty($value) + { + return $value === ''; + } + + /** + * Determine if the given string is not empty. + * + * @param string $value + * @return bool + */ + public static function isNotEmpty($value) + { + return $value !== ''; + } + /** * Convert a string to kebab case. * diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index fd98244285bf..b77910df6a1c 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -708,6 +708,26 @@ public function testIsJson() $this->assertFalse(Str::isJson([])); } + public function testIsEmpty() + { + $this->assertTrue(Str::isEmpty('')); + $this->assertFalse(Str::isEmpty('0')); + $this->assertFalse(Str::isEmpty(' ')); + $this->assertFalse(Str::isEmpty('hello')); + $this->assertFalse(Str::isEmpty('false')); + $this->assertFalse(Str::isEmpty('null')); + } + + public function testIsNotEmpty() + { + $this->assertFalse(Str::isNotEmpty('')); + $this->assertTrue(Str::isNotEmpty('0')); + $this->assertTrue(Str::isNotEmpty(' ')); + $this->assertTrue(Str::isNotEmpty('hello')); + $this->assertTrue(Str::isNotEmpty('false')); + $this->assertTrue(Str::isNotEmpty('null')); + } + public function testIsMatch() { $this->assertTrue(Str::isMatch('/.*,.*!/', 'Hello, Laravel!'));