我正在嘗試為同一驗證屬性創建兩個單獨的驗證訊息。有兩個使用“ before_or_equal ”的規則 -end_time必須是“ before_or_equal ” start_time 并且end_time必須在5:00(時間)之后。驗證有效,但我似乎找不到為后者創建有效的自定義訊息的方法。
我試圖通過在值中包含它來指定規則,但它似乎不起作用。
這就是目前自定義請求驗證的樣子end_time。
public function rules()
{
return [
'end_time' => ['after_or_equal:start_time', 'after_or_equal:5:00'],
];
}
public function messages()
{
return [
'end_time.after_or_equal' => 'Message 1',
'end_time.after_or_equal:5:00' => 'Message 2',
];
}
uj5u.com熱心網友回復:
您可以使用:date自定義錯誤訊息。
例子:
public function rules()
{
return [
'end_time' => ['after_or_equal:start_time', 'after_or_equal:5:00'],
];
}
public function messages()
{
return [
'end_time.after_or_equal' => 'the :attribute time must be after :date',
];
}
替換的值是驗證器第一個輸入的實際值
uj5u.com熱心網友回復:
我不知道我是否正確理解了你的問題,但你在尋找這樣的東西嗎?
public function rules()
{
return $this->messages("end_time", [
"after_or_equal",
"after_or_equal:5:00",
]);
}
public function messages(string $Key, array $CustomAttributes)
{
$Exceptions = [
"end_time" => [
"after_or_equal" => "Message 1",
"after_or_equal:5:00" => "Message 2"
]
];
$Exception = [
$Key => []
];
foreach ($CustomAttributes as $Attribute) {
array_push($Exception[$Key], $Exceptions[$Key][$Attribute]);
}
return $Exception;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/486260.html
