我在 Laravel 9 上的唯一驗證有問題
我想用不同的 category_id 和不同的月份、年份的資料進行驗證
例如我有資料:
{
category_id: 1
month: 2
year: 2022
}
如果我輸入
{
category_id: 1
month: 3
year: 2022
}
我期望資料被成功保存,如果資料像這樣:,它不能保存。
{
category_id: 1
month: 3
year: 2022
}
因為相同的 category_id 和月份和年份。
我的代碼:
$this->validate($request, [
'category_id' => [
'required',
Rule::unique('categories')
->where('month', '!=', $request->month)
->where('year', '!=', $request->year),
],
]);
如何在 Laravel 9 上撰寫此驗證?之前謝謝。
uj5u.com熱心網友回復:
不要使用'!='符號。
Rule::unique('categories')
->where('month', $request->month)
->where('year', $request->year)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/513287.html
標籤:php拉拉维尔网络
上一篇:for回圈中的JS超時
