Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
20 changes: 20 additions & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!'));
Expand Down