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 are 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();
}
}
Html code
<table class="table table-hover" data-toggle="table" id="table" data-click-to-select="true"> <thead> <tr> <th style="width:10%;" data-field="ActivityId">Select</th> <th style="width:30%;" data-field="ActivityName">Activity Name</th> <th style="width:30%;" data-field="Rate">Rate/Person</th> <th style="width:30%;">Nos. of person</th> </tr> </thead> <tbody> @foreach($loadactivity as $key=>$activity) <tr> <td> <input type="checkbox" name="data[]" value="0;{!! $activity->ActivityId !!};{!! $activity->Rate !!};0;0;{!! $activity->ActivityName !!}" /> </td> <td>{!! $activity->ActivityName !!}</td> <td>{!! $activity->Rate !!}</td> <td >{!! Form::text('txtnos[]','',['class' => 'form-control small-textbox ','txtnoid'=>$activity->ActivityId]) !!}</td> </tr> @endforeach </tbody> </table>
please help me