Laravel数组验证用于数组中的唯一属性,但不要求表中唯一 [英] Laravel array validation for unique attribute in array but not required to be unique in table
本文介绍了Laravel数组验证用于数组中的唯一属性,但不要求表中唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在php中有一个数组.我需要验证数组,以便每个abc_id在数组中都应该是唯一的,但在数据库表中并不需要是唯一的.
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'
]);
预先感谢.
推荐答案
您可以使用 distinct laravel array
验证规则.
You can use distinct rule of laravel array
validation.
$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());
这篇关于Laravel数组验证用于数组中的唯一属性,但不要求表中唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文