mattm591
4 years ago

[L5] Validating multiple file input

Posted 4 years ago by mattm591

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.

Please sign in or create an account to participate in this conversation.