Skip to content
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

Confirmation field override #48

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## v5

### Upgrading from v5.2 to v5.3

- Minimum Laravel version increased from `11.8` to `11.23.2`.

### Upgrading from v5.1 to v5.2

- Minimum Laravel version increased from `11.5` to `11.8`.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"minimum-stability": "stable",
"require": {
"php": "^8.2",
"laravel/framework": "^11.8"
"laravel/framework": "^11.23.2"
},
"require-dev": {
"ext-json": "*",
"orchestra/testbench": "^9.0",
"orchestra/testbench": "^9.4",
"phpunit/phpunit": "^10.5",
"laravel/pint": "1.13.9",
"larastan/larastan": "^2.0"
Expand Down
6 changes: 5 additions & 1 deletion src/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,12 @@ public static function can(string $ability, mixed ...$arguments): Can
*
* @link https://laravel.com/docs/11.x/validation#rule-confirmed
*/
public static function confirmed(): string
public static function confirmed(?string $confirmationFieldName = null): string
{
if ($confirmationFieldName !== null) {
return 'confirmed:'.$confirmationFieldName;
}

return 'confirmed';
}

Expand Down
4 changes: 2 additions & 2 deletions src/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ public function can(string $ability, mixed ...$arguments): self
*
* @link https://laravel.com/docs/11.x/validation#rule-confirmed
*/
public function confirmed(): self
public function confirmed(?string $confirmationFieldName = null): self
{
return $this->rule(Rule::confirmed());
return $this->rule(Rule::confirmed($confirmationFieldName));
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/RuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,28 @@ public static function ruleDataProvider(): array
],
'fails' => true,
],
'confirmed with override valid' => [
'data' => [
'field' => 'value',
'fieldConfirmation' => 'value',
'field_confirmation' => 'other-value',
],
'rules' => fn() => [
'field' => RuleSet::create()->confirmed('fieldConfirmation'),
],
'fails' => false,
],
'confirmed with override invalid' => [
'data' => [
'field' => 'value',
'fieldConfirmation' => 'other-value',
'field_confirmation' => 'value',
],
'rules' => fn() => [
'field' => RuleSet::create()->confirmed('fieldConfirmation'),
],
'fails' => true,
],
'contains valid' => [
'data' => [
'field' => ['a', 'b', 'c'],
Expand Down