php - Laravel array validation for unique attribute in array but not required to be unique in table
问题描述
I have an array in php. i need to validate array such that each abc_id should be unique in array but not required to be unique in database table.
$validator = Validator::make($request->all(), [
'tests.*.*.abc_id' => 'should not be same in array'
]);
Thanks in Advance.
解决方案
您可以使用不同的 laravelarray
验证规则。
$validator = Validator::make(
['products' =>
['product_id' => 1, 'quantity' => 5],
['product_id' => 1, 'quantity' => 99],
['product_id' => 2, 'quantity' => 1],
],
['products.*.product_id' => 'distinct']
);
dd($validator->passes());
推荐阅读
- agora.io - 录制 Agora 时只获得一个屏幕
- performance - Pytorch(GPU)中(低秩块)对角线与向量的有效乘法
- html - 如何使用 CSS 插入 LUI 图标“向下箭头”
- android - 如何从 Kotlin Android 应用程序连接到 Phoenix 频道?
- php - 如何使 smtp 设置为动态的?我收到一个错误参数 1 传递给 Illuminate\Mail\MailManager::getConfig()
- reactjs - 如何为我的对象中的每个数组项添加 2 个新属性
- ios - iOS中,RunLoop在一秒内循环多少次
- mysql - 如何在新表中导入列类型 json?
- css - 如何使 Angular Material 响应式?
- json - 我试图将我的嵌套 json 文件存储到 db 但它在索引中引发错误