Laravel:在更新操作时,为关联阵列输入请求添加唯一的验证规则
我正在执行更新操作,并具有下面的输入请求:
array:1 [
"buildings" => array:3 [
0 => array:4 [
"item_id" => 6
"florida_number" => "1006"
"serial_number" => "1002"
"building_id" => 6
]
1 => array:4 [
"item_id" => 7
"florida_number" => "1007"
"serial_number" => "1002"
"building_id" => 7
],
.....
.....
]
]
现在我想在 serial_number 字段上应用唯一的验证规则,该规则存储在 项目< /strong> 数据库中的表。
我需要照顾的是在检查唯一性时忽略当前项目ID。
I am doing update operation and have an input request like below:
array:1 [
"buildings" => array:3 [
0 => array:4 [
"item_id" => 6
"florida_number" => "1006"
"serial_number" => "1002"
"building_id" => 6
]
1 => array:4 [
"item_id" => 7
"florida_number" => "1007"
"serial_number" => "1002"
"building_id" => 7
],
.....
.....
]
]
Now I want to apply unique validation rule on serial_number field which is stored in items table in database.
The thing I need to take care of here is to ignore the current item id while checking uniqueness.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的解决方案是将以下规则添加到您的表格请求中:
The easiest solution is to add a rule like below to your form request: