У меня есть этот Laravel -5.8 код:
Контроллер
public function store(StoreLeaveRequestRequest $request)
{
if (! Gate::allows('leave_request_create')) {
return abort(401);
}
try {
$commencementDate = Carbon::parse($request->commencement_date);
$resumptionDate = Carbon::parse($request->resumption_date);
$leaverequest = HrLeaveRequest::create([
'leave_type_id' => $request->leave_type_id,
'commencement_date' => $commencementDate,
'resumption_date' => $resumptionDate,
]);
Session::flash('success', 'Leave Request is created successfully');
return redirect()->route('service.leave_requests.index');
}
catch (Exception $exception)
{
Session::flash('error', 'Action failed!');
return redirect()->route('service.leave_requests.index');
}
}
Также у меня есть этот код create.blade
<div class="col-sm-4">
<div class="form-group">
<label>Commencement Date:<span style="color:red;">*</span></label>
<input type="date" class="form-control" placeholder="dd/mm/yyyy" name="commencement_date" value="{{old('commencement_date')}}" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label>Resumption Date:<span style="color:red;">*</span></label>
<input type="date" class="form-control" placeholder="dd/mm/yyyy" name="resumption_date" value="{{old('resumption_date')}}" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label>Requested Days:</label>
<input type="number" name="no_of_days" class="form-control" value="{{old('no_of_days')}}" style="width: 100%;" disabled>
</div>
</div>
Javascript
<script type="text/javascript">
$(document).ready(function() {
$(function () {
$('#commencement_date').datetimepicker({
format: "YYYY-MM-DD"
});
$('#resumption_date').datetimepicker({
format: "YYYY-MM-DD"
});
});
});
</script>
Чего я хочу добиться, так это того, что onchange в resuration_date я хочу вычесть
commencement_date из resuration_date и загрузить результат в no_of_days