3 months ago

laravel validation rules

Posted 3 months ago by t0berius

I'm struggeling with laravel validation rules.

I've got the following fields:

'productPrice'  => 'required|numeric|min:1|max:100',

'reqAmount1'            => 'sometimes|nullable|integer|min:2|required_with:newproductPrice1',
'newproductPrice1'      => 'sometimes|nullable|numeric|required_with:reqAmount1|lt:productPrice|max:100',

How to extend the ruleset for a new


The input should be optional. Here's the "rule" set required:

-if reqAmount2 is filled reqAmount1 & newproductPrice1 & newproductPrice2 are required (!= null)
-if reqAmount2 is filled, it needs to be greather than reqAmount1 (the amount of purchased products needs to be larger than reqAmount1)
-if newproductPrice2 is filled, it needs to be less than newproductPrice1

Hope you understand the functionality itself, the seller should be able to define new product prices, depending on the amount a user is purchasing.

Using sometimes and nullable won't work for the new fields reqAmount2 and newproductPrice2 I think.

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