Skip to content

Commit 3ea6a3d

Browse files
[10.x] Added isUrl to Stringable. (#47689)
* Added `isUrl` to Stringable. * Added tests
1 parent ab74124 commit 3ea6a3d

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
@@ -322,6 +322,16 @@ public function isJson()
322322
return Str::isJson($this->value);
323323
}
324324

325+
/**
326+
* Determine if a given value is a valid URL.
327+
*
328+
* @return bool
329+
*/
330+
public function isUrl()
331+
{
332+
return Str::isUrl($this->value);
333+
}
334+
325335
/**
326336
* Determine if a given string is a valid UUID.
327337
*

tests/Support/SupportStringableTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public function testIsAscii()
3333
$this->assertFalse($this->stringable('ù')->isAscii());
3434
}
3535

36+
public function testIsUrl()
37+
{
38+
$this->assertTrue($this->stringable('https://laravel.com')->isUrl());
39+
$this->assertFalse($this->stringable('invalid url')->isUrl());
40+
}
41+
3642
public function testIsUuid()
3743
{
3844
$this->assertTrue($this->stringable('2cdc7039-65a6-4ac7-8e5d-d554a98e7b15')->isUuid());

0 commit comments

Comments
 (0)