[L5] Validating multiple file input

Posted 3 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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.