Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

murtaza1904's avatar

I want to validate data if the checkbox for particular form is checked. But it method is validating all at the same time.

public function rules()
    {
        return array_merge(
                (new PatientRequest())->rules(),
                (new ContactRequest())->rules(),
                (new ChoiceRequest())->rules(),
                (new EmployerRequest())->rules(),
                (new StatsRequest())->rules(),
                (new MiscRequest())->rules(),
                (new GuardianRequest())->rules(),
                (new PrimaryInsuranceRequest())->rules(),
                (new SecondaryInsuranceRequest())->rules(),
                (new TertiaryInsuranceRequest())->rules(),
            );
    }
0 likes
1 reply
Nihir's avatar

Than simply name the checkbox and put conditions on it like this here is a simple solution

public function post(Request $request){
	if($request->checkbox){
$validator = Validator::make($request->all,[
		'second-form-value'=>'required',
]);
}else{
$validator = Validator::make($request->all(),[
		'first-form-values'=>'required',
]);
}

Please or to participate in this conversation.