In Laravel,
I am using custom validation in my project to check whether mininum area having smaller value than maximum area. Just created the validation in Validator library
public function validate_less_than($attribute, $value, $parameters)
{
$other_value = $this->attributes[$parameters[0]];
if(!empty($value) && !empty($other_value))
return $value <= $other_value;
else
return true;
}
added validation message for “less_than”, in language file.
'less_than' => "The :attribute must be less than :other value",
and added replace placeholder function in validator library, to replace the :other placeholder
protected function replace_less_than($message, $attribute, $rule, $parameters)
{
return str_replace(':other', $parameters[0], $message);
}
my field names are like “min_area”, “max_area”, so I don’t want this field names in validation message, so i have added friendly names for these fields in language files. but “:other” placeholder not taking the friendly names which is specified in validation language file. is it only possible for “:attribute” placeholder?
It’s hard coded in validator.php at around line 856 (in current version 3.2.12).
You could run it from your replacer tough.
Note the
$this->attribute().