php - Laravel checkbox validation (O or 1) -
i validating checkbox here user must select one.
<label class="col-md-3 control-label" for="checkboxes">can resume </label> <div class="col-md-4"> <label class="checkbox-inline" for="checkboxes-0"> <input type="checkbox" name="canres[]" id="checkboxes-0" value="1"> yes </label> <label class="checkbox-inline" for="checkboxes-1"> <input type="checkbox" name="cannotres[]" id="checkboxes-1" value="0"> no </label> </div>
and on server side in controller method validating :
$validator = validator::make(input::get(), [ 'canres' => 'required', 'cannotres' => 'required' ]);
the validation fails because 1 checked , other required
want 1 checked. either cannotres
or canres
.
how can achieve ?
you can take use of validation method required_without_all
$validator = validator::make(input::get(), [ 'canres' => 'required_without_all:cannotresume', 'cannotres' => 'required_without_all:canresume' ]);
hope helps out.
Comments
Post a Comment