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 12, 2023
1 parent 0588737 commit cfa4fa1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,10 @@ protected function processRules(

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

$fieldForErrors = ($rule === 'field_exists') ? $originalField : $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 cfa4fa1

Please sign in to comment.