diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index 0cb76068e396..743a37d63473 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -322,6 +322,16 @@ public function isJson() return Str::isJson($this->value); } + /** + * Determine if a given value is a valid URL. + * + * @return bool + */ + public function isUrl() + { + return Str::isUrl($this->value); + } + /** * Determine if a given string is a valid UUID. * diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index e67d9cfa9165..a0c5f233c537 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -33,6 +33,12 @@ public function testIsAscii() $this->assertFalse($this->stringable('รน')->isAscii()); } + public function testIsUrl() + { + $this->assertTrue($this->stringable('https://laravel.com')->isUrl()); + $this->assertFalse($this->stringable('invalid url')->isUrl()); + } + public function testIsUuid() { $this->assertTrue($this->stringable('2cdc7039-65a6-4ac7-8e5d-d554a98e7b15')->isUuid());