Refactor push notification logic in afterSave method #157
@@ -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_id' => $user->id,
|
||||||
]);
|
// ]);
|
||||||
$user->notify(
|
// $user->notify(
|
||||||
new PushAlertNotification(
|
// 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,
|
||||||
|
'subscription_count' => $subscriptions->count(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user