Skip to content

Commit 40d7974

Browse files
[9.x] Add isUlid in Stringable (#45100)
* Add isUlid in `Stringable` * Add tests * Update Stringable.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 44ae14d commit 40d7974

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Illuminate/Support/Stringable.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,16 @@ public function isUuid()
320320
return Str::isUuid($this->value);
321321
}
322322

323+
/**
324+
* Determine if a given string is a valid ULID.
325+
*
326+
* @return bool
327+
*/
328+
public function isUlid()
329+
{
330+
return Str::isUlid($this->value);
331+
}
332+
323333
/**
324334
* Determine if the given string is empty.
325335
*

tests/Support/SupportStringableTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public function testIsUuid()
3939
$this->assertFalse($this->stringable('2cdc7039-65a6-4ac7-8e5d-d554a98')->isUuid());
4040
}
4141

42+
public function testIsUlid()
43+
{
44+
$this->assertTrue($this->stringable('01GJSNW9MAF792C0XYY8RX6QFT')->isUlid());
45+
$this->assertFalse($this->stringable('01GJSNW9MAF-792C0XYY8RX6ssssss-QFT')->isUlid());
46+
}
47+
4248
public function testIsJson()
4349
{
4450
$this->assertTrue($this->stringable('1')->isJson());

0 commit comments

Comments
 (0)