To make the code true when it is less than or equal to 30 minutes, the whereTime method should be modified to check if the difference between the start_time and the current time is less than or equal to 30 minutes. This can be achieved by using the diffInMinutes method of the Carbon instance. Here's the modified code:
public function getReminder()
{
$now = Carbon::now();
$startTime = $now->copy()->addMinutes(30);
$bookings = Booking::leftJoin('rooms', 'rooms.id', 'bookings.room_id')
->leftJoin('tenants', 'tenants.id', 'bookings.tenant_id')
->leftJoin('tenant_details', 'tenant_details.tenant_id', 'tenants.id')
->leftJoin('users', 'users.id', 'tenant_details.user_id')
->where('bookings.status', 'confirmed')
->where('start_time', '<=', $startTime)
->where('start_time', '>=', $now->subMinutes(30))
->select(
...
)
->get();
$successfulReminders = [];
foreach ($bookings as $booking) {
$users = User::where('email', $booking->email)->get();
foreach ($users as $user) {
$user->notify(new BookingReminderNotification($booking));
}
if ($users->isNotEmpty()) {
$successfulReminders[] = $booking->booking_id;
}
}
if (count($successfulReminders) > 0) {
return response()->json([
'message' => 'Reminders sent successfully for booking id: '
. implode(', ', $successfulReminders)
]);
} else {
return response()->json(['message' => 'No reminders were sent.']);
}
}
In the modified code, the whereTime method is replaced with where method to compare the start_time with the $startTime and $now variables. The $now variable is also modified to subtract 30 minutes to get the start time for the range.