Skip to content

Commit

Permalink
[10.x] Added isUrl to Stringable. (#47689)
Browse files Browse the repository at this point in the history
* Added `isUrl` to Stringable.

* Added tests
  • Loading branch information
michaelnabil230 authored Jul 9, 2023
1 parent ab74124 commit 3ea6a3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Support/Stringable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
6 changes: 6 additions & 0 deletions tests/Support/SupportStringableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 3ea6a3d

Please sign in to comment.