Enhance push notification logic in afterSave method to handle missing subscriptions and log warnings
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled

This commit is contained in:
dhanabalan
2026-01-30 12:13:01 +05:30
parent af0b17e674
commit 61467d88cd

View File

@@ -129,24 +129,46 @@ class EditRfqTransporterBid extends EditRecord
// ]); // ]);
// } // }
// } // }
foreach ($users as $user) foreach ($users as $user) {
{
$subscriptions = $user->pushSubscriptions()->get(); $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, 'user_id' => $user->id,
'subscription_count' => $subscriptions->count(), 'endpoint' => $subscription->endpoint,
'error' => $e->getMessage(),
]); ]);
foreach ($subscriptions as $subscription) { $subscription->delete();
\Notification::route('webpush', $subscription)
->notify(new PushAlertNotification(
'Rank Updated',
$body
));
}
} }
}
}
} }