Enhance push notification logic in afterSave method to handle missing subscriptions and log warnings #159

Merged
jothi merged 1 commits from ranjith-dev into master 2026-01-30 06:43:15 +00:00

View File

@@ -129,24 +129,46 @@ class EditRfqTransporterBid extends EditRecord
// ]);
// }
// }
foreach ($users as $user)
{
foreach ($users as $user) {
$subscriptions = $user->pushSubscriptions()->get();
Log::info('Sending push', [
Log::info('Checking push subscription for user', [
'user_id' => $user->id,
'name' => $user->name,
'subscription_count' => $subscriptions->count(),
]);
if ($subscriptions->isEmpty()) {
Log::warning('User has NO push subscription', [
'user_id' => $user->id,
]);
continue;
}
Log::info('Sending push notification', [
'user_id' => $user->id,
]);
foreach ($subscriptions as $subscription) {
try {
\Notification::route('webpush', $subscription)
->notify(new PushAlertNotification(
'Rank Updated',
$body
));
} catch (\Throwable $e) {
Log::warning('Removing invalid push subscription', [
'user_id' => $user->id,
'endpoint' => $subscription->endpoint,
'error' => $e->getMessage(),
]);
$subscription->delete();
}
}
}
}