Refactor push notification logic in afterSave method #157

Merged
jothi merged 1 commits from ranjith-dev into master 2026-01-30 06:36:03 +00:00

View File

@@ -104,31 +104,50 @@ class EditRfqTransporterBid extends EditRecord
// ); // );
// } // }
foreach ($users as $user) { // foreach ($users as $user) {
Log::info('Checking push subscription for user', [ // Log::info('Checking push subscription for user', [
'user_id' => $user->id, // 'user_id' => $user->id,
'name' => $user->name, // 'name' => $user->name,
'subscription_count' => $user->pushSubscriptions()->count(), // 'subscription_count' => $user->pushSubscriptions()->count(),
]); // ]);
if ($user->pushSubscriptions()->exists()) { // if ($user->pushSubscriptions()->exists()) {
Log::info('Sending push notification', [ // Log::info('Sending push notification', [
// 'user_id' => $user->id,
// ]);
// $user->notify(
// new PushAlertNotification(
// 'Rank Updated',
// $body
// )
// );
// }
// else {
// Log::warning('User has NO push subscription', [
// 'user_id' => $user->id,
// ]);
// }
// }
foreach ($users as $user)
{
$subscriptions = $user->pushSubscriptions;
Log::info('Sending push', [
'user_id' => $user->id, 'user_id' => $user->id,
'subscription_count' => $subscriptions->count(),
]); ]);
$user->notify(
new PushAlertNotification( foreach ($subscriptions as $subscription) {
\Notification::route('webpush', $subscription)
->notify(new PushAlertNotification(
'Rank Updated', 'Rank Updated',
$body $body
) ));
);
}
else {
Log::warning('User has NO push subscription', [
'user_id' => $user->id,
]);
} }
} }
} }
protected function getHeaderActions(): array protected function getHeaderActions(): array