I am trying to remove the required property from input field when the checkbox is unchecked but it's not working and when the checkbox is checked field should be required please help me thanks.
html view
<div class="col-md-2">
<input type="checkbox" id="scheduledis" name="checkbox[0]" class="schedule_discount" value="" >
<label for=""> Schedule Discount
</label>
</div>
<div class="input-group">
<input type="text" class="form-control datepicker-autoclose-1 dislay-required" required placeholder="Start Date" value="" name="start_date" >
<div class="input-group-append">
<span class="input-group-text">
<i class="md md-event-note">
</i>
</span>
</div>
<span class="text-danger">{{$errors->first('date') ?? null}}
</span>
</div>
jquery script
$('input[type="checkbox"]').change(function() {
//check if check if checked
$(this).is(':checked') ?
$('input[name=start_date]').prop('required', false) :
$('input[name=start_date]').prop('required', true);
$('input[name=end_date]').prop('required', false) :
$('input[name=end_date]').prop('required', true);
$('input[name=start_time]').prop('required', false) :
$('input[name=start_time]').prop('required', true);
$('input[name=end_time]').prop('required', false) :
$('input[name=end_time]').prop('required', true);
});