You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
When you need to use the same name for a field with the same slug in multiple validators that each used different nested keys, there is no way to define this in the translation file.
What you would need to do in the translation file is this:
In order to do this we can change Illuminate\Validations\Concerns\FormatsMessages method getDisplayableAttribute() to do this:
/** * Get the displayable name of the attribute. * * @param string $attribute * @return string */publicfunctiongetDisplayableAttribute($attribute)
{
$primaryAttribute = $this->getPrimaryAttribute($attribute);
$expectedAttributes = $attribute != $primaryAttribute
? [$attribute, $primaryAttribute] : [$attribute];
foreach ($expectedAttributesas$name) {
// The developer may dynamically specify the array of custom attributes on this// validator instance. If the attribute exists in this array it is used over// the other ways of pulling the attribute name for this given attributes.if (isset($this->customAttributes[$name])) {
return$this->customAttributes[$name];
}
// We allow for a developer to specify language lines for any attribute in this// application, which allows flexibility for displaying a unique displayable// version of the attribute name instead of the name used in an HTTP POST.if ($line = $this->getAttributeFromTranslations($name)) {
return$line;
}
// this is the change right here, we can change the name key// and then retry getting the line from the translations file$parts = explode('.', $name);
$name = array_pop($parts);
if ($line = $this->getAttributeFromTranslations($name)) {
return$line;
}
// end change
}
// When no language line has been specified for the attribute and it is also// an implicit attribute we will display the raw attribute's name and not// modify it with any of these replacements before we display the name.if (isset($this->implicitAttributes[$primaryAttribute])) {
return$attribute;
}
returnstr_replace('_', '', Str::snake($attribute));
}
I can provide a PR if this is acceptable. Thinking it may also be good to make it an opt-in only type of thing, where when you create a validator, we will store the property $nestedAttributeFallback as false by default, but you could turn it on for this functionality.
The text was updated successfully, but these errors were encountered:
When you need to use the same name for a field with the same slug in multiple validators that each used different nested keys, there is no way to define this in the translation file.
What you would need to do in the translation file is this:
Instead I just want to have this:
In order to do this we can change
Illuminate\Validations\Concerns\FormatsMessages
methodgetDisplayableAttribute()
to do this:I can provide a PR if this is acceptable. Thinking it may also be good to make it an opt-in only type of thing, where when you create a validator, we will store the property
$nestedAttributeFallback
asfalse
by default, but you could turn it on for this functionality.The text was updated successfully, but these errors were encountered: