I have a form with 3 fields - start date, end date and pattern. I want to pick the values from the input and check if those are empty. if not then compare the dates and perform action. By when I tried passing the value `$request->input('from')` in $status, it returned null.
my form:
<div class="modal-body">
<form action="App\Http\Controllers\HolidayController@addSchedule" method="POST" autocomplete="off" id="scheduleForm">
@include('partials.holidayFormModal')
</form>
</div>
holidayFormModal:
<link rel="stylesheet" href="{{ url('assets/custom/css/schedule/scheduleForm.css') }}">
<div class="form-group row col-md-12 date-picker">
<label class="col-sm-2 date-picker-label" for="from">
{{ __('messages.schedule_period') }}
</label>
<div class="input-group col-sm-4">
<input class="form-control" id="start_datepicker" type="text" name="from" autocomplete="off" readonly>
<span class="input-group-addon">
<i class="fas fa-calendar-alt"></i>
</span>
</div>
<div class="col-sm-2"></div>
<div class="input-group col-sm-4">
<input class="form-control" id="end_datepicker" type="text" name="to" autocomplete="off" readonly>
<span class="input-group-addon">
<i class="fas fa-calendar-alt"></i>
</span>
</div>
</div>
<div class="form-group row col-md-12 motif-picker">
<label class="col-sm-2 motif-label" for="meotif">
{{ __('messages.schedule_motif') }}
</label>
<input class="form-control col-sm-10" type="text" id="motif" name="motif" max="60">
</div>
<div class="col-md-11"></div>
<div class="col-md-1" id="schedule-submit">
<button class="btn" type="button" id="schedule_form_submit_button">
<i class="fas fa-check-circle fa-3x"></i>
</button>
</div>
web.php :
Route::get('/holidays', ['uses' => $controllerNamespace . 'HolidayController@index', 'as' => 'holidays']);
Route::post('/holidayAdd',['uses' => $controllerNamespace . 'HolidayController@addSchedule', 'as' => 'holidayAdd']);
HolidayController:
public function addSchedule(Request $request) {
$scheduleModelObj = new ScheduleModel;
$scheduleModelObj->from = $request->from;
$scheduleModelObj->to = $request->to;
$scheduleModelObj->motif = $request->motif;
$fromDate = str_replace('/', '-', $request->from);
$toDate = str_replace('/', '-', $request->to);
$f = date('Y-m-d', strtotime($fromDate));
$t = date('Y-m-d', strtotime($toDate));
if ($f == '' || $t == '' || $scheduleModelObj->motif == '') {
$returnMessage['date'] = __('messages.schedule_end_date_error');
$returnMessage['motif'] = __('messages.schedule_motif_error');
$status = 'error';
} else {
if ($f < $t) {
$scheduleModelObj->searchSchedule($scheduleModelObj->from, $scheduleModelObj->to);
$status = 'success';
}
$returnMessage['date'] = __('messages.schedule_end_date_error');
$returnMessage['motif'] = __('messages.schedule_motif_error');
$status = 'error';
}
return ['status' => $status, 'message' => $returnMessage];
}