update-import-validation-message

This commit is contained in:
Cihan Şentürk 2025-11-27 15:19:48 +03:00 committed by GitHub
parent 0c7fa0cf0d
commit 6cfd9410d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -122,7 +122,18 @@ abstract class Import implements HasLocalePreference, ShouldQueue, SkipsEmptyRow
} catch (ValidationException $e) {
foreach ($e->validator->failed() as $attribute => $value) {
foreach ($value as $rule => $params) {
$validator->addFailure($row . '.' . $attribute, $rule, $params);
if ($rule === 'In' && !empty($params)) {
$actual_value = $data[$attribute] ?? 'null';
$expected_values = implode(', ', $params);
$custom_message = trans('validation.in_detailed', [
'attribute' => $attribute,
'value' => $actual_value,
'values' => $expected_values
]);
$validator->errors()->add($row . '.' . $attribute, $custom_message);
} else {
$validator->addFailure($row . '.' . $attribute, $rule, $params);
}
}
}

View File

@ -66,6 +66,7 @@ return [
'image' => 'The :attribute must be an image.',
'in' => 'The selected :attribute is invalid.',
'in_array' => 'The :attribute field does not exist in :other.',
'in_detailed' => 'The :attribute value ":value" is invalid. Expected one of: :values',
'integer' => 'The :attribute must be an integer.',
'ip' => 'The :attribute must be a valid IP address.',
'ipv4' => 'The :attribute must be a valid IPv4 address.',