我的模型中有一個欄位days,現在我想在這一列中只保存integer或float值。
值可以是:
120.50.52.52.5
我試著使用numeric,但是它不允許我輸入float值:
$this->validate($request, [
'day' => 'required|numeric|min:1|max:50',
]);
非常感謝您的幫助
。謝謝
uj5u.com熱心網友回復:
如果沒有驗證規則幫助你,你可以使用閉包。
因此,首先嘗試這樣做:
'day' => 'required|numeric|min:0|max:50'。
如果它不作業,我們可以使用closures:
'days' => [...
'required',
'numeric',
function ($attribute, $value, $fail>>) {
if ($value <= 0) {
$fail($attribute.' must be greater than 0. ')。
}
},
'max:50',
],
請記住,numeric驗證,使用is_numeric內置PHP函式。
uj5u.com熱心網友回復:
你可以嘗試為你的情況定制驗證規則。 例子:
'day' => 'required|regex:/^d*(.d{2})?$/'
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/320607.html
標籤:
下一篇:用連接方式從兩個表中獲取資料
