Skip to content

Commit

Permalink
Merge pull request #8242 from kenjis/fix-validation-field_exists
Browse files Browse the repository at this point in the history
refactor: Validation rule field_exists
  • Loading branch information
kenjis authored Nov 28, 2023
2 parents b4f6af0 + 5f1d0a5 commit 9e8786c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ protected function processRules(
$arrayCallable = $isCallable && is_array($rule);

$passed = false;
$param = false;
/** @var string|null $param */
$param = null;

if (! $isCallable && preg_match('/(.*?)\[(.*)\]/', $rule, $match)) {
$rule = $match[1];
Expand Down Expand Up @@ -329,7 +330,7 @@ protected function processRules(
if ($rule === 'field_exists') {
$passed = $set->{$rule}($value, $param, $data, $error, $originalField);
} else {
$passed = ($param === false)
$passed = ($param === null)
? $set->{$rule}($value, $error)
: $set->{$rule}($value, $param, $data, $error, $field);
}
Expand All @@ -355,8 +356,6 @@ protected function processRules(
$value = json_encode($value);
}

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

$fieldForErrors = ($rule === 'field_exists') ? $originalField : $field;

// @phpstan-ignore-next-line $error may be set by rule methods.
Expand Down

0 comments on commit 9e8786c

Please sign in to comment.