Skip to content

Commit f24c53a

Browse files
committed
feat: improve error key
1 parent 3b0ff58 commit f24c53a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

system/Validation/Validation.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,14 @@ protected function processRules(
356356

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

359+
if ($rule === 'field_exists') {
360+
$fieldForErrors = $originalField;
361+
} else {
362+
$fieldForErrors = $field;
363+
}
364+
359365
// @phpstan-ignore-next-line $error may be set by rule methods.
360-
$this->errors[$field] = $error ?? $this->getErrorMessage(
366+
$this->errors[$fieldForErrors] = $error ?? $this->getErrorMessage(
361367
($this->isClosure($rule) || $arrayCallable) ? (string) $i : $rule,
362368
$field,
363369
$label,

tests/system/Validation/RulesTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,7 @@ public function testFieldExistsErrorMessage(): void
948948

949949
$this->assertFalse($this->validation->run($data));
950950
$this->assertSame(
951-
// This errror message is not perfect.
952-
['fiz.bar.baz' => 'The fiz.*.baz field must exist.'],
951+
['fiz.*.baz' => 'The fiz.*.baz field must exist.'],
953952
$this->validation->getErrors()
954953
);
955954
}

0 commit comments

Comments
 (0)