Skip to content

Commit cfa4fa1

Browse files
committed
feat: improve error key
1 parent 0588737 commit cfa4fa1

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

system/Validation/Validation.php

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

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

359+
$fieldForErrors = ($rule === 'field_exists') ? $originalField : $field;
360+
359361
// @phpstan-ignore-next-line $error may be set by rule methods.
360-
$this->errors[$field] = $error ?? $this->getErrorMessage(
362+
$this->errors[$fieldForErrors] = $error ?? $this->getErrorMessage(
361363
($this->isClosure($rule) || $arrayCallable) ? (string) $i : $rule,
362364
$field,
363365
$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)