public function rules()
{
$rules = [
'name' => 'required|max:500',
'code' => 'required|unique:products|max:500',
'description' => 'required'
];
$nbr = count($this->input('image')) - 1;
foreach(range(0, $nbr) as $index) {
$rules['image.' . $index] = 'image|max:4000';
}
return $rules;
}
Mar 22, 2015
9
Level 1
[L5] Validating multiple file input
I have a multiple file upload which sends an array of image files to Laravel. The images array can be accessed fine, but the validation rules I specified are always returning false because the value is an array, not a file.
I'm using a Request with a rules function, defined as:
public function rules()
{
$rules = [
'name' => 'required|max:500',
'code' => 'required|unique:products|max:500',
'description' => 'required',
'image' => 'image|max:4000',
];
return $rules;
}
I considered extending the validate function in Illuminate\Validation\Validator, but didn't have much luck (not really sure how to define it, tried a few different ways but always either got errors or it just didn't have any effect).
Can anyone suggest a way I can handle validation of an array of files globally, without having to do more manual validation by iterating my files.
Level 52
6 likes
Please or to participate in this conversation.