When to use sometimes validation rule?
In some scenarios, you want to apply certain validation if a particular field is present then this Laravel validation rule plays important role.
In the above input we are not passing age input therefore in the controller it doesn’t validate age input but in bellow scenario, we are passing name as well as age so it is validating both inputs
Here we are passing both name and age, therefore, it validates both name and age.
Complex Conditional Validation
Sometimes you may wish to add validation rules based on more complex conditional logic,let see how to achieve this with example.
Above code shows how to apply complex validation in Laravel
if age is bellow 60 then the salary field is compulsory.
Here user inserted age 45, therefore, the salary field is compulsory.