t0berius
1 week ago
187
9
Laravel

laravel validation required_with not working as expected

Posted 1 week ago by t0berius

Using the following validation ruleset:

        'productImage1'         => 'nullable|sometimes|mimes:jpeg,jpg,png|max:2000',
        'productImage2'         => 'nullable|sometimes|mimes:jpeg,jpg,png|max:2000|required_with:productImage1',
        'productImage3'         => 'nullable|sometimes|mimes:jpeg,jpg,png|max:2000|required_with:productImage2',
        'productImage4'         => 'nullable|sometimes|mimes:jpeg,jpg,png|max:2000|required_with:productImage3',

Using the validation rules I want to make sure, the images are only uploaded in the correct order. At the moment a user can choose for example only productImage3 and the validation will pass, any idea how to prevent this?

Seems like required_with:productImage2 is not working as expected for this scenario?

Validation should pass the following as valid:

-no upload detected (for all fields)

-uploads are in the correct order, meaning productImage1 can be filled, or productImage1 and productImage2 or productImage1,productImage2 and productImage3

Please sign in or create an account to participate in this conversation.