На моей странице запроса на отпуск у меня есть одна строка поиска в столбце длительности отпуска, в столбце длительности отпуска указываются даты, сначала - дата начала отпуска, а 2 - дата окончания отпуска.
Я хочу сделать это, в строке поиска, если я напишу дату между этими датами, чем получу вывод этой записи.
Моя база данных mongodb
leavedate является переменной, с которой я нахожу записи.
Вот код моего контроллера
public function listOfLeave(Request $request)
{
$allLeaves = null;
if (
!empty($request->input('name')) ||
!empty($request->input('leaveType')) ||
!empty($request->input('leaveDate')) ||
!empty($request->input('appliedDate')) ||
!empty($request->input('status'))
)
{
$flg = false;
if (!empty($request->input('name')))
{
$flg = true;
$allLeaves=LeaveManagement::where('name', 'LIKE', "%{$request->input('name')}%");
}
if (!empty($request->input('leaveType')))
{
if($flg)
{
$allLeaves=$allLeaves->orWhere('type', 'LIKE', "%{$request->input('leaveType')}%");
}
else
{
$allLeaves=LeaveManagement::where('type', 'LIKE', "%{$request->input('leaveType')}%");
}
}
if (!empty($request->input('leaveDate')))
{
if ($flg)
{
$allLeaves = $allLeaves->orWhere('end', '>=', $request->input('leaveDate'))
->orWhere('start', '<=', $request->input('leaveDate'));
}
else
{
$allLeaves = LeaveManagement::where('end', '>=', $request->input('leaveDate'));
}
}
if (!empty($request->input('appliedDate')))
{
if($flg)
{
$allLeaves=$allLeaves->orWhere('start', 'LIKE', "%{$request->input('appliedDate')}%");
}
else
{
$allLeaves=LeaveManagement::where('start', 'LIKE', "%{$request->input('appliedDate')}%");
}
}
if (!empty($request->input('status')))
{
if($flg)
{
$allLeaves=$allLeaves->orWhere('status', 'LIKE', "%{$request->input('status')}%");
}
else
{
$allLeaves=LeaveManagement::where('status', 'LIKE', "%{$request->input('status')}%");
}
}
$allLeaves = $allLeaves ->orderBy('name', 'ASC')
->orderBy('type', 'ASC')
->orderBy('start', 'ASC')
->orderBy('start', 'ASC')
->orderBy('status', 'ASC')
->paginate(25);
return view('pages.newleaverequest')->with(['allLeaves'=>$allLeaves]);
}
else
{
$allLeaves=LeaveManagement::orderBy('name', 'ASC')->paginate(25);
}
$allLeaves->appends(array('name'=>Input::get('name')));
return view('pages.newleaverequest', compact('allLeaves'));
}
Вот мой файл просмотра
<form action="{{ route('manage_leave') }}" method="GET" role="search">
<div class="row">
<div class="form-group">
<input type="text" class="form-control " id="search1" name="name" placeholder="Employee Name">
<select class="custom-select form-control col-md-2" id="search5" name="leaveType">
<option value="">Leave Type</option>
<option value="casual">Casual Leave</option>
<option value="medical">Medical Leave</option>
<option value="early">Early Leave</option>
</select>
<input type="date" class="form-control " id="search3" name="leaveDate" placeholder="Leave Date">
<input type="date" class="form-control " id="search4" name="appliedDate" placeholder="Applied Date">
<select class="custom-select form-control col-md-2" id="search5" name="status">
<option value="">Status</option>
<option value="Pending">Pending</option>
<option value="Approved">Approved</option>
<option value="Rejected">Rejected</option>
</select>
  
<button class="btn btn-info" type="submit"><i class="fa fa-search "></i></button>
</div>
</div>
</form>
@if(isset($allLeaves))
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Employee Name</th>
<th>Leave Type</th>
<th>Leave Duration</th>
<th>Applied On</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@if($allLeaves != null)
@foreach($allLeaves as $leave)
<tr>
<td> {{ $leave->name }} </td>
<td> {{ $leave->type }} </td>
<td>
{{ date('d-m-Y', strtotime($leave->start)) }} To
{{ date('d-m-Y', strtotime($leave->end)) }}
</td>
<td> {{ date('d-m-Y', strtotime($leave->start)) }} </td>
<td>
@if($leave['status']=='Pending')
<span class="badge badge-pill badge-warning" style="color:white;font-size: 90%;font-weight:bold;">Pending</span>
@elseif($leave['status']=='Approved')
<span class="badge badge-pill badge-success" style="color:white;font-size: 90%;font-weight:bold;">Approved</span>
@else
<span class="badge badge-pill badge-danger" style="color:white;font-size: 90%;font-weight:bold;">Rejected</span>
@endif
</td>
<td>
<a href="{{route('handle_leave', $leave->id)}}" class="btn btn-info text-white">Details</a>
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
<div>
{{ $allLeaves->render() }}
@endif
</div>
</div>
</div>
</div>