Marcolino922's avatar

Show image upload validation errors

I can't show validation errors in a form that allows multiple images to be uploaded. It only shows the "Required" error, but those about the maximum size or extensions allowed don't show them.

Where am I wrong?


$request->validate([
            'image' => 'required',
            'image.*' => 'mimes:jpeg,jpg,png|max:2048'
        ]);

                            @error('image')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
0 likes
1 reply
newbie360's avatar
@if ($errors->first('image') || $errors->first('image.*'))
    <span class="invalid-feedback" role="alert">
        <strong>{{ $message }}</strong>
    </span>
@endif

Edit: oops my bad, $message only exists when use @error

this should work

@if ($errors->hasAny(['image', 'image.*']))
    <span class="invalid-feedback" role="alert">
        <strong>{{ $errors->first('image') ?: $errors->first('image.*') }}</strong>
    </span>
@endif

Please or to participate in this conversation.