This question already has an answer here:
In my blade file there is a search bar on leave duration column, leave duration column contail startDate & endDate,
In my database i have 2 fields start date and end date, and if i search a date who lies between startDate & endDate than it will give me output,
here in my controller file
public function listOfLeave(Request $request)
{
$from = date('1001-01-01');
$to = date('9999-12-31');
$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('username', 'LIKE', "%{$request->input('name')}%");
}
if (!empty($request->input('leaveType'))) {
if ($flg) {
$allLeaves = $allLeaves->orWhere('typeOfLeave', 'LIKE', "%{$request->input('leaveType')}%");
} else {
$allLeaves = LeaveManagement::where('typeOfLeave', 'LIKE', "%{$request->input('leaveType')}%");
}
}
if (!empty($request->input('leaveDate'))) {
if ($flg) {
$allLeaves = $allLeaves->orWhereBetween('startDate', 'LIKE', "%{$request->input('leaveDate')}%");
} else {
$allLeaves = LeaveManagement::where('startDate', 'LIKE', "%{$request->input('leaveDate')}%");
}
}
if (!empty($request->input('appliedDate'))) {
if ($flg) {
$allLeaves = $allLeaves->orWhere('startDate', 'LIKE', "%{$request->input('appliedDate')}%");
} else {
$allLeaves = LeaveManagement::where('startDate', '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('username', 'ASC')
->orderBy('typeOfLeave', 'ASC')
->orderBy('startDate', 'ASC')
->orderBy('startDate', 'ASC')
->orderBy('status', 'ASC')
->paginate(2);
return view('pages.newleaverequest')->with(['allLeaves' => $allLeaves]);
} else {
$allLeaves = LeaveManagement::orderBy('username', 'ASC')->paginate(5);
}
$allLeaves->appends(['name' => Input::get('name')]);
return view('pages.newleaverequest', compact('allLeaves'));
}
How can i get records who lies between startdate and enddate???
</div>