fix: per package fixed

This commit is contained in:
2025-12-12 19:27:56 +03:30
parent e5831b86d2
commit 882d26337c
3 changed files with 112 additions and 12 deletions
+34 -11
View File
@@ -47,13 +47,34 @@ public function handle(): int
return Command::SUCCESS;
}
foreach ($reminders as $reminder) {
$user = $reminder->user;
$packageName = $reminder->packageName;
foreach ($reminders as $reminder) {
$packageName = $reminder->packageName;
if ($reminder->last_repeat?->addDays($reminder->repeat_days)->isFuture()) {
continue;
}
// Check if reminder has a specific user
if ($reminder->user_id) {
$user = $reminder->user;
$relation = $user->packageNames()->where('package_names.id', $packageName->id)->first();
$fcmToken = $relation?->pivot?->fcm_token;
if ($fcmToken) {
SendPushJob::dispatch(
user: $user,
title: $reminder->title,
packageName: $packageName,
description: $reminder->description ?? '',
data: $reminder->data ?? []
);
}
}
// Otherwise, send to all users that have this package
else {
$users = $packageName->users()->whereNotNull('package_name_user.fcm_token')->get();
foreach ($users as $user) {
$fcmToken = $user->packageNames()->where('package_names.id', $packageName->id)->first()->pivot->fcm_token;
if (!$fcmToken) continue;
SendPushJob::dispatch(
user: $user,
@@ -62,12 +83,14 @@ public function handle(): int
description: $reminder->description ?? '',
data: $reminder->data ?? []
);
$reminder->last_repeat = $now;
$reminder->save();
$this->info("Queued push notification for reminder {$reminder->id}.");
}
}
$reminder->last_repeat = now();
$reminder->save();
$this->info("Queued push notification for reminder {$reminder->id}.");
}
return Command::SUCCESS;
}