Change the orWhere.
$query->Where('status', '<' 3);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Required reservation history o/p, An end date less than current date with status confirmed(1) or cancelled(2) and also end date greater than equal to current date with status cancelled(2) only.
$employeeId = $request->employee_id; $currentDate = Carbon::now()->toDateString();
$reservationsHistory = Booking::where(['user_id' => $employeeId])
->whereDate('end_date', '<', $currentDate)
->where(function ($query) {
$query->Where('status', 1);
$query->orWhere('status', 2);
})
->orderByDesc('created_at')
->get();
$reservationsHistory = Booking::where(['user_id' => $employeeId])
->whereDate('end_date', '>=', $currentDate)
->Where('status', 2)
->orderByDesc('created_at')
->get();
return $reservationsHistory;
$reservationsHistory = Booking::query()
->where(function($query) use($currentDate, $employeeId) {
$query->where('end_date','<',$currentDate)
->whereIn('status',[1,2])
->where(['user_id' => $employeeId]);
})
->orWhere(function($query) use($currentDate,$employeeId) {
$query->where('end_date','>=',$currentDate)
->where('status',2])
->where(['user_id' => $employeeId]);
}
->orderByDesc('created_at')
->get();
Please or to participate in this conversation.