Refactor push notification logic in afterSave method to streamline subscription checks and improve logging #160

Merged
jothi merged 1 commits from ranjith-dev into master 2026-01-30 06:51:41 +00:00
Showing only changes of commit 17d54cc52e - Show all commits

View File

@@ -129,45 +129,36 @@ class EditRfqTransporterBid extends EditRecord
// ]);
// }
// }
foreach ($users as $user) {
$subscriptions = $user->pushSubscriptions()->get();
Log::info('Checking push subscription for user', [
'user_id' => $user->id,
'name' => $user->name,
'subscription_count' => $subscriptions->count(),
]);
foreach ($users as $user) {
if ($subscriptions->isEmpty()) {
Log::warning('User has NO push subscription', [
'user_id' => $user->id,
]);
continue;
}
$count = $user->pushSubscriptions()->count();
Log::info('Sending push notification', [
'user_id' => $user->id,
]);
Log::info('Checking push subscription for user', [
'user_id' => $user->id,
'name' => $user->name,
'subscription_count' => $count,
]);
foreach ($subscriptions as $subscription) {
try {
\Notification::route('webpush', $subscription)
->notify(new PushAlertNotification(
if ($count == 0) {
Log::warning('User has NO push subscription', [
'user_id' => $user->id,
]);
continue;
}
Log::info('Sending push notification', [
'user_id' => $user->id,
]);
// ✅ 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();
}
}
}
}