8000 [11.x] Fluent string validation by mrvipchien · Pull Request #54488 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[11.x] Fluent string validation #54488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add active url for string rule validation
  • Loading branch information
cuong.tt committed Feb 6, 2025
commit 3a57ccf8f60b8ff7554fe719dcae3c3bd6b9ff9c
10 changes: 10 additions & 0 deletions src/Illuminate/Validation/Rules/StringRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ public function same(string $field): static
return $this->addRule('same:'.$field);
}

/**
* The field under validation must be a valid A or AAAA record.
*
* @return $this
*/
public function activeUrl(): static
{
return $this->addRule('active_url');
}
Comment on lines +299 to +307
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really be part of the string validation and not of a separate URI validation rule like the email validation rule?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/**
* The field under validation must be a valid URL.
*
Expand Down
6 changes: 6 additions & 0 deletions tests/Validation/ValidationStringRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ public function testSameRule()
$this->assertEquals('string|same:foo', (string) $rule);
}

public function testActiveUrlRule()
{
$rule = Rule::string()->activeUrl();
$this->assertEquals('string|active_url', (string) $rule);
}

public function testUrlRule()
{
$rule = Rule::string()->url();
Expand Down
0