diff --git a/UPGRADE.md b/UPGRADE.md index 8105cfe..c79c63b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -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`. diff --git a/composer.json b/composer.json index 6dcc5e3..d0bf08a 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/src/Rule.php b/src/Rule.php index e84c346..bcddb9e 100644 --- a/src/Rule.php +++ b/src/Rule.php @@ -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'; } diff --git a/src/RuleSet.php b/src/RuleSet.php index b336037..b60afd1 100644 --- a/src/RuleSet.php +++ b/src/RuleSet.php @@ -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)); } /** diff --git a/tests/Unit/RuleTest.php b/tests/Unit/RuleTest.php index 63a9218..b612672 100644 --- a/tests/Unit/RuleTest.php +++ b/tests/Unit/RuleTest.php @@ -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'],