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

massum's avatar

required_with in laravel for input filed as array

i have a table with checkbox as array and textbox as also array. what i want to achieve is when the user checked a checkbox it should validate that input textbox should not be empty.

public function roombooking(Request $request)
    {


      $messsages = array(
        'check.required'=>'No room was selected.Please select room to proceed for booking !',
        'txtnos.required|numeric'=>'Please enter no of persons',
    );
      $rules = array(
        'check'=>'required',
        'txtnos'=>'required_with:data', //txtnos is a array input filed  and data is a array checkbox 
        );
      $validator = Validator::make($request->all(),  $rules,$messsages
            );
      if ($validator->fails()) {

            return Redirect::back()
                ->withErrors($validator)
                ->withinput();
                
        }
}
0 likes
0 replies

Please or to participate in this conversation.