Skip to content

Commit

Permalink
Confirmation field override (#48)
Browse files Browse the repository at this point in the history
* update: added confirmation override support

* build: updated minimum Laravel version
  • Loading branch information
erik-perri authored Sep 12, 2024
1 parent 158272a commit 02c06f8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
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

0 comments on commit 02c06f8

Please sign in to comment.