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