Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Web Push Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Push Notifications Integration: The package is a direct fit for Laravel-based applications requiring web push notifications (e.g., real-time alerts, marketing campaigns, or user engagement features). It aligns with Laravel’s event-driven and queue-based architectures, enabling asynchronous push delivery.
  • Service Worker Compatibility: Works seamlessly with Service Workers (client-side) and Laravel’s backend, bridging the gap between server-side logic and browser push APIs.
  • VAPID Authentication: Supports VAPID (Voluntary Application Server Identification), a critical security standard for push notifications, ensuring compliance with modern browser requirements (Chrome, Firefox, Safari).
  • Queue System: Leverages Laravel’s queue system (via queueNotification()) for batch processing, reducing server load and improving scalability.

Integration Feasibility

  • Laravel Ecosystem Synergy:
    • Service Providers: Can be bootstrapped via Laravel’s ServiceProvider for centralized configuration (VAPID keys, default TTL, etc.).
    • Events/Listeners: Triggers (e.g., push.notification.sent) can integrate with Laravel’s event system for analytics or retries.
    • Jobs/Queues: Push notifications can be dispatched as Laravel Jobs (e.g., SendPushNotificationJob) for reliability.
  • Database Storage: Subscription data (e.g., endpoint, keys) can be stored in Laravel’s database (e.g., push_subscriptions table) for persistence.
  • Frontend Integration: Works with JavaScript Service Workers (e.g., Laravel Mix/Vite) to handle push subscriptions and notifications.

Technical Risk

  • PHP Version Dependency: Requires PHP 8.2+ (Laravel 10+). Older Laravel versions (e.g., 8/9) would need a downgraded package version (v9.x), introducing compatibility risks (e.g., deprecated features, security patches).
  • Cryptographic Requirements: Mandates OpenSSL with elliptic curve support (for VAPID). Missing this may break VAPID authentication, requiring server configuration adjustments.
  • Payload Size Limits: Hard 3052-byte payload limit may constrain rich notifications (e.g., images, long text). Workarounds include:
    • Compressing payloads (e.g., gzip).
    • Storing large content on a CDN and referencing it via URL.
  • Browser-Specific Quirks:
    • Safari may require urgency field (workaround: enforce defaults).
    • Firefox/Chrome may have endpoint expiration issues (requires subscription validation logic).
  • Rate Limiting: Push services (e.g., FCM, Mozilla) impose throttling. Laravel’s queue system can help manage this, but monitoring is needed.

Key Questions

  1. Authentication Strategy:
    • How will VAPID keys be stored securely? (e.g., Laravel’s config, environment variables, or a secrets manager like AWS Secrets Manager?)
    • Will the same VAPID keys be used across all environments (dev/staging/prod), or will unique keys be generated per environment?
  2. Subscription Management:
    • How will expired/invalid subscriptions be detected and cleaned up? (e.g., periodic validation jobs)
    • Will subscriptions be tied to Laravel users (e.g., user_id in the database)?
  3. Performance Optimization:
    • Should reuseVAPIDHeaders be enabled for batch sends to reduce overhead?
    • What batch size (batchSize) will be used for flush() to balance memory and performance?
  4. Error Handling:
    • How will failed pushes be retried? (e.g., Laravel’s failed_jobs table + exponential backoff)
    • Will analytics be logged for failed pushes (e.g., endpoint errors, payload size issues)?
  5. Frontend Integration:
    • How will the Service Worker be registered and updated? (e.g., Laravel Mix/Vite, or a separate build process)
    • Will push notifications trigger Laravel events (e.g., NotificationReceived) for further processing?

Integration Approach

Stack Fit

  • Laravel Core:
    • Service Provider: Register the WebPush client with VAPID keys and default options.
    • Config File: Store VAPID keys (subject, publicKey, privateKey) in config/webpush.php.
    • Database: Add a push_subscriptions table with fields: user_id, endpoint, keys (JSON), is_active, created_at.
  • Queue System:
    • Dispatch push notifications as Laravel Jobs (e.g., SendPushNotificationJob) to decouple sending from the main request flow.
    • Use queue workers (e.g., Redis, database) to handle batch processing.
  • Frontend:
    • Service Worker: Register using the Push API and subscribe with the VAPID public key.
    • JavaScript: Handle push events and display notifications (e.g., using Laravel’s frontend stack like Inertia.js or Livewire).

Migration Path

  1. Phase 1: Setup and Configuration
    • Add minishlink/web-push to composer.json.
    • Generate VAPID keys and store them securely (e.g., .env or AWS Secrets Manager).
    • Create a Laravel Service Provider to initialize WebPush with config.
    • Set up the push_subscriptions database table.
  2. Phase 2: Frontend Integration
    • Implement Service Worker registration in the frontend (e.g., using Laravel Mix/Vite).
    • Add subscription logic to send the PushSubscription object to Laravel (e.g., via API endpoint).
    • Store subscriptions in the database.
  3. Phase 3: Backend Logic
    • Create a SendPushNotification job to handle push delivery.
    • Implement a queue listener to process jobs asynchronously.
    • Add error handling and retries for failed pushes.
  4. Phase 4: Testing and Optimization
    • Test with all supported browsers (Chrome, Firefox, Safari).
    • Monitor payload sizes and adjust compression if needed.
    • Optimize batch sizes and VAPID header reuse for performance.

Compatibility

  • Laravel Versions:
    • Laravel 10+: Use minishlink/web-push:^10.0 (PHP 8.2+).
    • Laravel 9: Use minishlink/web-push:^9.0 (PHP 8.1).
    • Laravel 8: Use minishlink/web-push:^8.0 (PHP 8.0, but OpenSSL elliptic curve support may be missing).
  • Browser Support:
    • Chrome, Firefox, and Safari support the modern push API with VAPID.
    • Legacy formats (e.g., old Firefox/Chrome) are supported but may require additional logic.
  • Database:
    • Subscriptions can be stored in any Laravel-supported database (MySQL, PostgreSQL, SQLite).
    • JSON fields (e.g., keys) should be used for the subscription object.

Sequencing

  1. Initialization:
    • Bootstrap 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'),
                ],
            ]);
        });
    }
    
  2. Subscription Storage:
    • Create a model (PushSubscription) to manage subscriptions in the database.
    // app/Models/PushSubscription.php
    class PushSubscription extends Model
    {
        protected $casts = [
            'keys' => 'json',
        ];
    }
    
  3. Sending Notifications:
    • Dispatch a job when a push is needed (e.g., after a user action or event).
    // 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);
                }
            }
        }
    }
    
  4. Frontend Subscription:
    • Register the Service Worker and subscribe in the frontend (e.g., using Alpine.js or Inertia.js).
    // 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,
            })
        );
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky