ralphmorris's avatar

Validating array of images. L5.2 Format Request.

Hi,

I am trying to get validation working on an array of images.

I have an input:

{!! Form::file('images[]', ['multiple' => 'multiple']) !!}

And a Form Request with the following rules:

    public function rules()
    {
        $rules = [
            'images.*'     => ['required', 'image'],
        ];

        return $rules;
    }

The above 'required' check works perfectly and forces the user to upload at least one image as expected.

However the 'image' check seems to work in that it won't let me upload a txt file, however it doesn't throw out any message on failed validation.

Does anyone have an idea what may be happening?

Thanks in advance.

Ralph

0 likes
2 replies
mikefolsom's avatar

So you get an error message if the 'required' validation fails, but no error message if the 'image' validation fails?

Have you tried inspecting the $errors variable?

ralphmorris's avatar

Thanks for your reply.

That is correct. The error message comes through fine for 'required' but not for 'image'.

I have done a var_export($errors) on both instances and can see the 'required' message in the variable. But when testing the 'image' validation, it does fail but no message comes though.

Please or to participate in this conversation.