Skip to content

Instantly share code, notes, and snippets.

@jangaraev
Last active May 18, 2022 04:38
Show Gist options
  • Save jangaraev/aa9753420f01ed7c89d79afaf063441b to your computer and use it in GitHub Desktop.
Save jangaraev/aa9753420f01ed7c89d79afaf063441b to your computer and use it in GitHub Desktop.
Update 'required' validation to use translatable field names
Validator::replacer('required', function ($message, $attribute, $rule, $parameters) {
$attributeSanitized = $attribute;
if (Str::endsWith($attribute, '_id')) {
$attributeSanitized = substr($attribute, 0, -3);
}
$friendlyAttributeName = str_replace('_', ' ', $attribute);
$newAttributeName = Lang::has('fields.' . $attributeSanitized)
? __('fields.' . $attributeSanitized)
: $friendlyAttributeName;
return str_replace($friendlyAttributeName, $newAttributeName, $message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment