Compare commits

...

2 Commits

Author SHA1 Message Date
6d32be91f7 Merge pull request 'Enhance push notification logic in afterSave method to handle missing subscriptions and log warnings' (#159) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Reviewed-on: #159
2026-01-30 06:43:15 +00:00
dhanabalan
61467d88cd 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
2026-01-30 12:13:01 +05:30

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,
'subscription_count' => $subscriptions->count(),
'endpoint' => $subscription->endpoint,
'error' => $e->getMessage(),
]);
foreach ($subscriptions as $subscription) {
\Notification::route('webpush', $subscription)
->notify(new PushAlertNotification(
'Rank Updated',
$body
));
}
$subscription->delete();
}
}
}
}