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

Webpush Bundle Laravel Package

bentools/webpush-bundle

Symfony bundle to send Web Push notifications using the Web Push protocol. Manage user-to-subscription associations (multi-device and shared devices) with your own persistence (Doctrine or custom). Includes VAPID key generation and backend APIs for subscriptions.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony/Laravel Compatibility: The package is designed for Symfony (not Laravel), leveraging Symfony’s dependency injection, Doctrine ORM, and event system. While Laravel shares some PHP/Symfony ecosystem components (e.g., Doctrine, VAPID keys), direct integration would require abstraction layers (e.g., custom service wrappers, event dispatchers) to bridge Symfony-specific features (e.g., UserSubscriptionManagerRegistry, PushMessageSender).
  • Web Push Protocol Alignment: The bundle aligns with the Web Push Protocol (VAPID keys, subscription management) and integrates with frontend libraries like webpush-client. This is a strong fit for any PHP app needing push notifications.
  • Decoupled Design: The bundle enforces separation of concerns (e.g., UserSubscription entity, UserSubscriptionManagerInterface), making it adaptable to custom persistence (e.g., Laravel’s Eloquent) with minimal refactoring.

Integration Feasibility

  • Core Dependencies:
    • Symfony Components: UserInterface, EventDispatcher, Doctrine (optional but recommended). Laravel equivalents exist but require mapping (e.g., Illuminate\Contracts\Auth\AuthenticatableUserInterface).
    • VAPID Keys: The bundle uses minishlink/web-push (PHP Web Push library), which is Laravel-compatible. Key generation (webpush:generate:keys) can be replicated via custom Artisan commands.
    • Frontend: Requires webpush-client (JavaScript) for subscription handling. No Laravel-specific changes needed here.
  • Key Challenges:
    • Service Registry: Symfony’s UserSubscriptionManagerRegistry would need a Laravel equivalent (e.g., a facade or service container binding).
    • Routing: Symfony’s /webpush endpoint must be mapped to Laravel’s routing system (e.g., Route::post('/webpush', ...)).
    • Event System: Symfony’s EventDispatcher → Laravel’s Events or Listeners.

Technical Risk

  • Medium-High Risk:
    • Symfony-Specific Abstractions: The bundle’s reliance on Symfony’s UserSubscriptionManagerRegistry and PushMessageSender introduces refactoring risk. A Laravel port would require rewriting these as custom services.
    • Doctrine ORM: While Laravel supports Doctrine, the bundle’s UserSubscription entity assumes Doctrine annotations. Laravel’s Eloquent or custom attribute mappings would need adjustment.
    • Unstable Version: The package notes it’s not yet stable, implying potential breaking changes in future releases.
  • Mitigation:
    • Wrapper Layer: Create Laravel-specific services to abstract Symfony dependencies (e.g., LaravelWebPushManager implementing UserSubscriptionManagerInterface).
    • Testing: Validate subscription persistence, VAPID key handling, and notification dispatch in a Laravel environment.
    • Fallback: Use the underlying minishlink/web-push library directly if bundle integration proves too cumbersome.

Key Questions

  1. Is the bundle’s Symfony-specific codebase too tightly coupled for Laravel?
    • Follow-up: Can we abstract the UserSubscriptionManagerRegistry and PushMessageSender into Laravel-compatible services?
  2. How will we handle the /webpush endpoint in Laravel’s routing system?
    • Follow-up: Will we need a custom controller or middleware to process subscription/unsubscription requests?
  3. What’s the fallback plan if the bundle’s instability causes integration issues?
    • Follow-up: Can we use minishlink/web-push directly with Laravel’s queue system for notifications?
  4. How will we manage VAPID key generation in Laravel?
    • Follow-up: Can we replicate webpush:generate:keys as an Artisan command?
  5. Are there Laravel-specific push notification use cases not covered by this bundle?
    • Follow-up: For example, integrating with Laravel’s built-in queue workers or Horizon for async notifications.

Integration Approach

Stack Fit

  • Laravel Compatibility:
    • Core: The bundle’s Web Push Protocol implementation (minishlink/web-push) is Laravel-compatible. Focus on abstracting Symfony-specific components.
    • ORM: Doctrine is optional; Laravel’s Eloquent can replace the UserSubscription entity with minimal changes (e.g., use Illuminate\Database\Eloquent\Model).
    • Events: Replace Symfony’s EventDispatcher with Laravel’s Events or Listeners.
    • Routing: Map Symfony’s /webpush route to Laravel’s Route::post('/webpush', ...) with a custom controller.
  • Frontend: No changes needed; webpush-client works agnostically of the backend framework.

Migration Path

  1. Phase 1: Dependency Setup

    • Install the bundle via Composer (despite Symfony focus):
      composer require bentools/webpush-bundle
      
    • Generate VAPID keys via a custom Artisan command (replacing webpush:generate:keys):
      // app/Console/Commands/GenerateVapidKeys.php
      use minishlink\webpush\Vapid;
      
      public function handle() {
          $vapid = new Vapid();
          $this->info("Public Key: " . $vapid->getPublicKey());
          $this->info("Private Key: " . $vapid->getPrivateKey());
      }
      
    • Configure keys in .env:
      WEB_PUSH_PUBLIC_KEY=...
      WEB_PUSH_PRIVATE_KEY=...
      
  2. Phase 2: Entity & Manager Abstraction

    • Create a Laravel-compatible UserSubscription model:
      // app/Models/UserSubscription.php
      namespace App\Models;
      use Illuminate\Database\Eloquent\Model;
      use BenTools\WebPushBundle\Model\Subscription\UserSubscriptionInterface;
      
      class UserSubscription extends Model implements UserSubscriptionInterface {
          // Implement required methods (getUser(), getEndpoint(), etc.)
      }
      
    • Build a Laravel UserSubscriptionManager:
      // app/Services/LaravelUserSubscriptionManager.php
      namespace App\Services;
      use App\Models\UserSubscription;
      use BenTools\WebPushBundle\Model\Subscription\UserSubscriptionManagerInterface;
      use Illuminate\Support\Facades\Hash;
      
      class LaravelUserSubscriptionManager implements UserSubscriptionManagerInterface {
          public function hash(string $endpoint, $user): string {
              return Hash::make($endpoint);
          }
          // Implement other methods using Eloquent...
      }
      
    • Register the manager in Laravel’s service container (AppServiceProvider):
      $this->app->bind(
          \BenTools\WebPushBundle\Model\Subscription\UserSubscriptionManagerInterface::class,
          \App\Services\LaravelUserSubscriptionManager::class
      );
      
  3. Phase 3: Routing & Endpoint

    • Add a route in routes/web.php:
      Route::post('/webpush', [WebPushController::class, 'handleSubscription']);
      
    • Create a controller to handle subscriptions/unsubscriptions:
      // app/Http/Controllers/WebPushController.php
      use BenTools\WebPushBundle\WebPushEvents;
      use Illuminate\Http\Request;
      
      class WebPushController {
          public function handleSubscription(Request $request) {
              // Parse subscription data and dispatch Symfony-like events
              event(new WebPushEvents($request->input()));
          }
      }
      
  4. Phase 4: Notification Dispatch

    • Replace Symfony’s PushMessageSender with a Laravel service:
      // app/Services/LaravelPushMessageSender.php
      use minishlink\webpush\WebPush;
      
      class LaravelPushMessageSender {
          public function send(PushNotification $notification) {
              $webPush = new WebPush(
                  env('WEB_PUSH_PUBLIC_KEY'),
                  env('WEB_PUSH_PRIVATE_KEY'),
                  env('WEB_PUSH_SUBJECT', request()->getHost())
              );
              $webPush->sendNotification($notification->getSubscription(), $notification->getPayload());
          }
      }
      
    • Bind it in AppServiceProvider:
      $this->app->bind(
          \BenTools\WebPushBundle\Sender\PushMessageSender::class,
          \App\Services\LaravelPushMessageSender::class
      );
      
  5. Phase 5: Event Listeners

    • Replace Symfony event subscribers with Laravel listeners:
      // app/Listeners/NotifyOnOrderPlaced.php
      use App\Events\OrderPlaced;
      use BenTools\WebPushBundle\Model\Subscription\UserSubscriptionManagerRegistry;
      
      class NotifyOnOrderPlaced {
          public function handle(OrderPlaced $event) {
              $sender = app(PushMessageSender::class);
              $sender->send(new PushNotification($event->order->customer->subscriptions, "Order placed!"));
          }
      }
      
    • Register the listener in EventServiceProvider:
      protected $listen = [
          OrderPlaced::class => [NotifyOnOrderPlaced::class],
      ];
      

Compatibility

  • High Compatibility:
    • Web Push Protocol: Fully compatible via `min
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
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
spatie/mailcoach-vapor