minishlink/web-push
PHP library to send Web Push notifications to browser push endpoints (RFC 8030). Handles VAPID and payload encryption, supports batching and reporting, and works with modern PHP (8.2+) via Composer for integrating push into your backend.
queueNotification()) for batch processing, reducing server load and improving scalability.ServiceProvider for centralized configuration (VAPID keys, default TTL, etc.).push.notification.sent) can integrate with Laravel’s event system for analytics or retries.SendPushNotificationJob) for reliability.endpoint, keys) can be stored in Laravel’s database (e.g., push_subscriptions table) for persistence.v9.x), introducing compatibility risks (e.g., deprecated features, security patches).urgency field (workaround: enforce defaults).config, environment variables, or a secrets manager like AWS Secrets Manager?)user_id in the database)?reuseVAPIDHeaders be enabled for batch sends to reduce overhead?batchSize) will be used for flush() to balance memory and performance?failed_jobs table + exponential backoff)NotificationReceived) for further processing?WebPush client with VAPID keys and default options.subject, publicKey, privateKey) in config/webpush.php.push_subscriptions table with fields: user_id, endpoint, keys (JSON), is_active, created_at.SendPushNotificationJob) to decouple sending from the main request flow.minishlink/web-push to composer.json..env or AWS Secrets Manager).WebPush with config.push_subscriptions database table.PushSubscription object to Laravel (e.g., via API endpoint).SendPushNotification job to handle push delivery.minishlink/web-push:^10.0 (PHP 8.2+).minishlink/web-push:^9.0 (PHP 8.1).minishlink/web-push:^8.0 (PHP 8.0, but OpenSSL elliptic curve support may be missing).keys) should be used for the subscription object.WebPush in Laravel’s AppServiceProvider with VAPID keys and default options.// app/Providers/AppServiceProvider.php
public function boot(): void
{
$this->app->singleton(WebPush::class, function ($app) {
return new WebPush([
'VAPID' => [
'subject' => config('webpush.vapid.subject'),
'publicKey' => config('webpush.vapid.public_key'),
'privateKey' => config('webpush.vapid.private_key'),
],
]);
});
}
PushSubscription) to manage subscriptions in the database.// app/Models/PushSubscription.php
class PushSubscription extends Model
{
protected $casts = [
'keys' => 'json',
];
}
// app/Jobs/SendPushNotification.php
class SendPushNotification implements ShouldQueue
{
public function handle()
{
$webPush = app(WebPush::class);
$subscription = PushSubscription::find($this->subscriptionId);
$webPush->queueNotification($subscription, $this->payload);
$results = $webPush->flush();
foreach ($results as $report) {
if (!$report->isSuccess()) {
$this->handleFailure($report);
}
}
}
}
// resources/js/service-worker.js
self.addEventListener('push', (event) => {
const data = event.data?.json();
event.waitUntil(
self.registration.showNotification(data.title, {
body: data.body,
icon: data.icon,
})
);
});
How can I help you explore Laravel packages today?