输入数组可以有很多文档,但是每个文档中的照片既可以是一个文件,也可以是一个链接。如何正确检查数组中的每个元素?
我试着这样做,但它并不像我期望的那样工作
<?php
namespace Modules\Documents\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class DocumentsStoreRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'documents' => 'sometimes|array',
'documents.*.type' => 'in:certificate,license',
'documents.*.photo' => match($this->hasFile('documents.*.photo')) {
true => 'sometimes|mimes:png,jpg,jpeg|max:4096|nullable',
default => 'sometimes|string|url|nullable'
}
];
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
}
1条答案
按热度按时间h7appiyu1#
我设法克服了这个缺陷