如何解决Laravel |验证数组内每个元素的唯一性
用户可以将一系列图像上传到我的应用程序,而这些图像在我的数据库中已经不存在。
上载新文件时,我会存储文件的MD5哈希值,然后可以使用此值检查它是否已存在。
我使用自定义的FormRequest进行验证:
public function rules()
{
return [
'pictures' => 'required|array|min:1','pictures.*' => [
'required','image','mimes:jpg,png,jpeg','max:5120',Rule::unique('files')->where(function ($query) {
//How to get the current item of this array to check?
//Is it a good idea?
//$query->where('hash',$currentImageHash )
})
]
];
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。