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

Create your UserSubscription class

First, you have to implement BenTools\WebPushBundle\Model\Subscription\UserSubscriptionInterface.

It's a simple entity which associates:

  1. Your user entity
  2. The subscription details - it will store the JSON representation of the PushSubscription javascript object.
  3. A hash of the endpoint (or any string that could help in retrieving it).

You're free to use Doctrine or anything else.

Example class:

# src/Entity/UserSubscription.php

namespace App\Entity;

use BenTools\WebPushBundle\Model\Subscription\UserSubscriptionInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * [@ORM](https://github.com/ORM)\Entity()
 */
class UserSubscription implements UserSubscriptionInterface
{

    /**
     * [@var](https://github.com/var) int
     *
     * [@ORM](https://github.com/ORM)\Id()
     * [@ORM](https://github.com/ORM)\GeneratedValue(strategy="AUTO")
     * [@ORM](https://github.com/ORM)\Column(type="integer")
     */
    private $id;

    /**
     * [@var](https://github.com/var) User
     * [@ORM](https://github.com/ORM)\ManyToOne(targetEntity="App\Entity\User")
     * [@ORM](https://github.com/ORM)\JoinColumn(nullable=false)
     */
    private $user;

    /**
     * [@var](https://github.com/var) string
     *
     * [@ORM](https://github.com/ORM)\Column(type="string")
     */
    private $subscriptionHash;

    /**
     * [@var](https://github.com/var) array
     *
     * [@ORM](https://github.com/ORM)\Column(type="json")
     */
    private $subscription;

    /**
     * UserSubscription constructor.
     * [@param](https://github.com/param) User   $user
     * [@param](https://github.com/param) string $subscriptionHash
     * [@param](https://github.com/param) array  $subscription
     */
    public function __construct(User $user, string $subscriptionHash, array $subscription)
    {
        $this->user = $user;
        $this->subscriptionHash = $subscriptionHash;
        $this->subscription = $subscription;
    }

    /**
     * [@return](https://github.com/return) int
     */
    public function getId(): ?int
    {
        return $this->id;
    }

    /**
     * [@inheritDoc](https://github.com/inheritDoc)
     */
    public function getUser(): UserInterface
    {
        return $this->user;
    }

    /**
     * [@inheritDoc](https://github.com/inheritDoc)
     */
    public function getSubscriptionHash(): string
    {
        return $this->subscriptionHash;
    }

    /**
     * [@inheritDoc](https://github.com/inheritDoc)
     */
    public function getEndpoint(): string
    {
        return $this->subscription['endpoint'];
    }

    /**
     * [@inheritDoc](https://github.com/inheritDoc)
     */
    public function getPublicKey(): string
    {
        return $this->subscription['keys']['p256dh'];
    }

    /**
     * [@inheritDoc](https://github.com/inheritDoc)
     */
    public function getAuthToken(): string
    {
        return $this->subscription['keys']['auth'];
    }
    

    /**
     * Content-encoding (default: aesgcm).
     *
     * [@return](https://github.com/return) string
     */
    public function getContentEncoding(): string
    {
        return $this->subscription['content-encoding'] ?? 'aesgcm';
    }

}

Previous: Installation

Next: The UserSubscription Manager

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