T
T
thevalakas2017-03-27 22:45:30
Laravel
thevalakas, 2017-03-27 22:45:30

Why does laravel validator skip empty image array?

Hello here is the code

$validator = Validator::make($request->all(), [
            'image.*' => 'required|image',
            'descr.*' => 'string|nullable|max:10000',
            'board.*' => 'integer',
            'link.*' => 'url|nullable'
        ]);

        if ($validator->fails()) {
            return redirect('/upload')->withErrors($validator);
        }

accepts an array of images from the form and for some reason skips if the array is empty.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
thevalakas, 2017-03-28
@thevalakas

$validator = Validator::make($request->all(), [
            'image' => 'required',
            'image.*' => 'image',
            'descr.*' => 'string|nullable|max:10000',
            'board.*' => 'integer',
            'link.*' => 'url|nullable'
        ]);

        if ($validator->fails()) {
            return redirect('/upload')->withErrors($validator);
        }

I did it like this, everything works

D
Dmitry Evgrafovich, 2017-03-27
@Tantacula

'image' => 'required|array'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question