Refactor push notification logic in afterSave method to streamline subscription checks and improve logging
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:21:28 +05:30
parent 61467d88cd
commit 17d54cc52e

View File

@@ -129,17 +129,19 @@ class EditRfqTransporterBid extends EditRecord
// ]);
// }
// }
foreach ($users as $user) {
$subscriptions = $user->pushSubscriptions()->get();
$count = $user->pushSubscriptions()->count();
Log::info('Checking push subscription for user', [
'user_id' => $user->id,
'name' => $user->name,
'subscription_count' => $subscriptions->count(),
'subscription_count' => $count,
]);
if ($subscriptions->isEmpty()) {
if ($count == 0) {
Log::warning('User has NO push subscription', [
'user_id' => $user->id,
]);
@@ -150,24 +152,13 @@ class EditRfqTransporterBid extends EditRecord
'user_id' => $user->id,
]);
foreach ($subscriptions as $subscription) {
try {
\Notification::route('webpush', $subscription)
->notify(new PushAlertNotification(
// ✅ THIS IS ALL YOU NEED
$user->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();
}
}
}
}