get(); foreach ($recordsToUpdate as $record) { $managerestaurant = ManageRestaurant::where('id', $record->manage_restaurants_xid)->first(); $restTime = RestaurantTimeInterval::select('time_hours')->where('manage_restaurants_xid', $managerestaurant->id)->first(); $stateTime = TimeInterval::select('time_hours')->where('manage_state_xid', $managerestaurant->state_xid)->first(); $restTimeHours = $restTime ? $restTime->time_hours : 0; $stateTimeHours = $stateTime ? $stateTime->time_hours : 0; Log::info('Rest time interval time_hours: ' . $restTimeHours); Log::info('State time interval time_hours: ' . $stateTimeHours); $customerData = IamPrincipal::where('id', $record->iam_principal_xid) ->where('notification_status', 1) ->where('principal_type_xid', 3) ->first(); if ($managerestaurant && $managerestaurant->is_active == 1) { $redeemDate = Carbon::parse($record->redeem_date); // Calculate the state time plus record time $stateHourPlusTimeOfRecord = $redeemDate->copy()->addHours($stateTimeHours); Log::info('state time' . $stateHourPlusTimeOfRecord); $currentTime = Carbon::now(); if ($currentTime > $stateHourPlusTimeOfRecord) { // Only proceed if state time condition is met $restHourPlusTimeOfRecord = $redeemDate->copy()->addHours($restTimeHours); Log::info('Restaurant time ' . $restHourPlusTimeOfRecord); if ($currentTime > $restHourPlusTimeOfRecord) { $record->update([ 'is_redeem' => 0, 'count' => $record->count + 1, 'is_redeemption_undone' => 0, 'redeemption_undone_date' => null, ]); $restImage = ListingImageUrl('restaurant_images', $managerestaurant->image); $title = "Your " . $managerestaurant->name . " Reinstate successfully"; $message = "Your " . $managerestaurant->name . " Reinstate successfully"; $content_type = 'Restaurant Reinstate'; $imageUrl = $restImage; onesignalhelper::sendNotificationApi( $customerData->one_signal_player_id, $title, $message, $content_type, $imageUrl, $id = null ); Log::info('Reinstate of record done at ' . now()); onesignalhelper::StoreNotificationDetails($customerData->id, $content_type, $title, $restImage); } } } } } catch (\Exception $e) { Log::error('Reinstate function failed: ' . $e->getMessage()); } } }