Skip to content

Commit

Permalink
feat: improve error key
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Nov 8, 2023
1 parent 3b0ff58 commit f24c53a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 7 additions & 1 deletion system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,14 @@ protected function processRules(

$param = ($param === false) ? '' : $param;

if ($rule === 'field_exists') {
$fieldForErrors = $originalField;
} else {
$fieldForErrors = $field;
}

// @phpstan-ignore-next-line $error may be set by rule methods.
$this->errors[$field] = $error ?? $this->getErrorMessage(
$this->errors[$fieldForErrors] = $error ?? $this->getErrorMessage(
($this->isClosure($rule) || $arrayCallable) ? (string) $i : $rule,
$field,
$label,
Expand Down
3 changes: 1 addition & 2 deletions tests/system/Validation/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,7 @@ public function testFieldExistsErrorMessage(): void

$this->assertFalse($this->validation->run($data));
$this->assertSame(
// This errror message is not perfect.
['fiz.bar.baz' => 'The fiz.*.baz field must exist.'],
['fiz.*.baz' => 'The fiz.*.baz field must exist.'],
$this->validation->getErrors()
);
}
Expand Down

0 comments on commit f24c53a

Please sign in to comment.