Reputation: 149
Currently, I have two dates inside the database such as depart_date and return_date. For the view blade, the user must select the accident_date which is the accident_date must be between depart_date and return_date. So, before the the user submit the form, the form will check either the accident_date is exist between depart_date and return_date or not. I have created the sql command inside the controller. But, it gave me an error.
Error : syntax error, unexpected ''=>'' (T_CONSTANT_ENCAPSED_STRING), expecting ')'
Controller:
$startdate = InsuranceEnrollment::select('depart_date')
->where($request->accident_date '=>', 'depart_date') AND ($request->accident_date
'<=', 'return_date');
dd($startdate);
View blade:
<div class="form-group">
<label class="form-control-label form-control-sm">Accident </label>
<div class="input-group">
<input type="text" placeholder="" class="form-control date-picker"
data-datepicker-color="primary" name="accident_date" required>
</div>
Upvotes: 0
Views: 271
Reputation: 3972
Your where clause is not in proper way, here's how to do it.
$startdate = InsuranceEnrollment::select('depart_date')->where([
'depart_date' <= $request->accident_date,
'return_date' => $request->accident_date,
])->get();
Upvotes: 1
Reputation: 13394
The comparison condition need to be like this, so the $request->accident_date
will between these two dates.
depart_date <= accident_date AND return_date >= accident_date
You need to use WHERE ... AND...
like this:
$startdate = InsuranceEnrollment::select('depart_date')
->where('depart_date', '<=', $request->accident_date)
->where('return_date', '>=', request->accident_date);
Upvotes: 1