Last active
May 18, 2022 04:38
-
-
Save jangaraev/aa9753420f01ed7c89d79afaf063441b to your computer and use it in GitHub Desktop.
Update 'required' validation to use translatable field names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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