Laravelでは、
プロジェクトでカスタム検証を使用して、最小領域の値が最大領域よりも小さいかどうかを確認しています。バリデーターライブラリで検証を作成しました
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;
}
言語ファイルに「less_than」の検証メッセージを追加しました。
'less_than' => "The :attribute must be less than :other value",
:otherプレースホルダーを置き換えるために、バリデーターライブラリにreplaceplaceholder関数を追加しました
protected function replace_less_than($message, $attribute, $rule, $parameters)
{
return str_replace(':other', $parameters[0], $message);
}
私のフィールド名は「min_area」、「max_area」のようなものなので、検証メッセージにこのフィールド名を含めたくないので、言語ファイルにこれらのフィールドのわかりやすい名前を追加しました。ただし、「:other」プレースホルダーは、検証言語ファイルで指定されているフレンドリ名を使用しません。「:attribute」プレースホルダーでのみ可能ですか?