validation icon indicating copy to clipboard operation
validation copied to clipboard

Attribute aliases should replace all instances of field names in validation error messages

Open thomasfw opened this issue 6 years ago • 2 comments

For example, when using the same: rule, the message is "The :attribute must be same with :field", which gives us:

The New Password (again) must be same with new_password

Ideally the attribute alias should be used on the new_password field too. The field name often means nothing to the end user especially if they're not readable. So we want this...

The New Password (again) must be same with New Password

If you don't have time to look into this, could you give me a heads up on where the message aliases are filled and i'll work on a PR?

thomasfw avatar Mar 19 '19 20:03 thomasfw

I would like to bump this thread. I facing similar issue. Same class message:

//class
protected $message = "The :attribute must be same with :field";

//my code
$validator = new Validator($this->request);
$rules = [
	'password' => 'min:6',
	'confirmPassword' => 'required_with:password|same:password',
	'email' => 'email',
	'confirm_email' => 'same:email',
];
$alias = [
	'password' => Func::translate('password'),
	'confirmPassword' => Func::translate('confirm_password'),
	'email' => Func::translate('email'),
	'confirm_email' => Func::translate('confirm_email'),
];

$validator->setValidation($rules,$alias);
try {
	$validator->validate();
} catch (ExceptionValidator $e){
	return $this->view->renderFail($e->getMessage());
}

now the issue when getting fail translation for "confirm_password" field but the same field that must have same value "password" (:field) is not translated.

itsKnight847 avatar Mar 07 '22 15:03 itsKnight847

has any one got a workaround this issue?

itsKnight847 avatar Mar 17 '22 15:03 itsKnight847