7 Commits

Author SHA1 Message Date
dhanabalan
4a796a670a Refactor WebPushSubscription logic to streamline subscription creation
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
2026-01-31 18:05:10 +05:30
dhanabalan
4577f67d0a Fix CSRF token handling and update fetch URL for push subscription
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
2026-01-31 18:04:26 +05:30
dhanabalan
be2151a072 Fix fetch URL in push notification subscription to include leading slash
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
2026-01-31 18:01:42 +05:30
dhanabalan
a4251ae532 Add print PDF route and update WebPushSubscription logic for user subscriptions
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
2026-01-31 18:00:36 +05:30
dhanabalan
93d55765ae Remove unused CSRF token in push notification registration script
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
2026-01-31 17:59:00 +05:30
dhanabalan
17d54cc52e 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
2026-01-30 12:21:28 +05:30
dhanabalan
61467d88cd 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
2026-01-30 12:13:01 +05:30
4 changed files with 90 additions and 32 deletions

View File

@@ -129,24 +129,37 @@ class EditRfqTransporterBid extends EditRecord
// ]);
// }
// }
foreach ($users as $user)
{
$subscriptions = $user->pushSubscriptions()->get();
Log::info('Sending push', [
foreach ($users as $user) {
$count = $user->pushSubscriptions()->count();
Log::info('Checking push subscription for user', [
'user_id' => $user->id,
'subscription_count' => $subscriptions->count(),
'name' => $user->name,
'subscription_count' => $count,
]);
foreach ($subscriptions as $subscription) {
\Notification::route('webpush', $subscription)
->notify(new PushAlertNotification(
if ($count == 0) {
Log::warning('User has NO push subscription', [
'user_id' => $user->id,
]);
continue;
}
Log::info('Sending push notification', [
'user_id' => $user->id,
]);
// ✅ THIS IS ALL YOU NEED
$user->notify(new PushAlertNotification(
'Rank Updated',
$body
));
}
}
}

View File

@@ -65,7 +65,6 @@
},
body: JSON.stringify(subscription)
});
alert("Push notifications enabled ✅");
}
</script>

View File

@@ -25,12 +25,15 @@ use App\Http\Controllers\ObdController;
use App\Http\Controllers\PalletController;
use App\Http\Controllers\PdfController;
use App\Http\Controllers\PlantController;
use App\Http\Controllers\PrintController;
use App\Http\Controllers\ProductionStickerReprintController;
use App\Http\Controllers\SapFileController;
use App\Http\Controllers\StickerMasterController;
// use App\Http\Controllers\TelegramController;
use App\Http\Controllers\TestingPanelController;
use App\Http\Controllers\UserController;
use App\Models\WebPushSubscription;
use Filament\Facades\Filament;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
@@ -185,3 +188,46 @@ Route::post('file/store', [SapFileController::class, 'store'])->name('file.store
// Route::post('send-telegram', [TelegramController::class, 'sendMessage']);
// Route::post('invoice-exit', [InvoiceValidationController::class, 'handle']);
Route::post('/print-pdf', [PrintController::class, 'print']);
Route::post('/push/subscribe', function (Request $request) {
$user = Filament::auth()->user();
abort_if(!$user, 401);
$request->validate([
'endpoint' => 'required|string',
'keys.p256dh' => 'required|string',
'keys.auth' => 'required|string',
]);
// WebPushSubscription::updateOrCreate(
// ['endpoint' => $request->endpoint],
// [
// 'subscribable_type' => get_class($user),
// 'subscribable_id' => $user->id,
// 'public_key' => $request->keys['p256dh'],
// 'auth_token' => $request->keys['auth'],
// 'content_encoding' => $request->contentEncoding ?? 'aesgcm',
// ]
// );
WebPushSubscription::updateOrCreate(
[
'endpoint' => $request->endpoint,
'subscribable_type' => get_class($user),
'subscribable_id' => $user->id,
],
[
'public_key' => $request->keys['p256dh'],
'auth_token' => $request->keys['auth'],
'content_encoding' => $request->contentEncoding ?? 'aesgcm',
]
);
return response()->json(['success' => true]);
});

View File

@@ -58,30 +58,30 @@ use App\Http\Livewire\CustomLogin;
'keys.auth' => 'required|string',
]);
// WebPushSubscription::updateOrCreate(
// ['endpoint' => $request->endpoint],
// [
// 'subscribable_type' => get_class($user),
// 'subscribable_id' => $user->id,
// 'public_key' => $request->keys['p256dh'],
// 'auth_token' => $request->keys['auth'],
// 'content_encoding' => $request->contentEncoding ?? 'aesgcm',
// ]
// );
WebPushSubscription::updateOrCreate(
['endpoint' => $request->endpoint],
[
'endpoint' => $request->endpoint,
'subscribable_type' => get_class($user),
'subscribable_id' => $user->id,
],
[
'public_key' => $request->keys['p256dh'],
'auth_token' => $request->keys['auth'],
'content_encoding' => $request->contentEncoding ?? 'aesgcm',
]
);
// WebPushSubscription::updateOrCreate(
// [
// 'endpoint' => $request->endpoint,
// 'subscribable_type' => get_class($user),
// 'subscribable_id' => $user->id,
// ],
// [
// 'public_key' => $request->keys['p256dh'],
// 'auth_token' => $request->keys['auth'],
// 'content_encoding' => $request->contentEncoding ?? 'aesgcm',
// ]
// );
return response()->json(['success' => true]);
});