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
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user