0

I am new in Laravel I want to need some validation if I checked checkbox then in front of input field will validate Required|Numeric|min:1

Please Help.

As per below imageenter image description here

1 Answer 1

1

You are looking for required_if.

So, you could have the following rules in your Form Request or your Validator.

return [
    'systolic_blood_pressure_high' => 'nullable|numeric|min:1|required_if:has_systolic_bp,on',
    'systolic_blood_pressure_low'  => 'nullable|numeric|min:1|required_if:has_systolic_bp,on',
];

Assuming you have a checkbox with name has_systolic_bp and it is checked, the fields systolic_blood_pressure_high and systolic_blood_pressure_low will be required.

You also need to mark them as nullable as by default Laravel will consider them as invalid because of the TrimStrings and ConvertEmptyStringsToNull middlewares.

For more information, check the documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.