jeudi 17 mai 2018

Laravel validate all images in array (with different input names)

How would I run a validator for every image thats in a request, when the form file names are always different.

My form file names can range from file1 all the way to section_1_image[0][].

I need to create a validation that I can paste in every controller, that checks the post request and validates ALL files if it has them

This is what I have so far

    $validator = Validator::make($request->all(), [
        'items' => 'array',
    ]);

    $validator->each('items', [
        '*'       => 'max:50'
    ]);

    if ($validator->fails()) {
        echo 'Error';
        exit;
    }

But this doesn't seem to do anything, it just gets ignored?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire