Skip to content

Commit 9670eb2

Browse files
committed
docs: update readme
1 parent 38e6fb4 commit 9670eb2

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ __These keys must be safely stored and should not change.__
7272

7373
## Usage
7474

75-
Now you can use the channel in your `via()` method inside the notification and send a web push notification:
75+
Now you can use the channel in your `via()` method inside the notification and send a generic web push notification:
7676

7777
```php
7878
use Illuminate\Notifications\Notification;
@@ -107,6 +107,44 @@ class AccountApproved extends Notification
107107
}
108108
```
109109

110+
This package also supports [Declarative Web Push messages](https://www.w3.org/TR/push-api/#declarative-push-message), which aim to reduce the complexity of using push on the web in general and address some challenges of generic web push notifications like privacy concerns & battery life on mobile by making a client-side service worker optional while remaining fully backwards compatible.
111+
112+
```php
113+
use Illuminate\Notifications\Notification;
114+
use NotificationChannels\WebPush\DeclarativeWebPushMessage;
115+
use NotificationChannels\WebPush\WebPushChannel;
116+
117+
class AccountApproved extends Notification
118+
{
119+
public function via($notifiable)
120+
{
121+
return [WebPushChannel::class];
122+
}
123+
124+
public function toWebPush($notifiable, $notification)
125+
{
126+
return (new DeclarativeWebPushMessage)
127+
->title('Approved!')
128+
->icon('/approved-icon.png')
129+
->body('Your account was approved!')
130+
->action('View account', 'view_account', 'https://myapp.com/accounts')
131+
->navigate('https://myapp.com');
132+
// ->data(['id' => $notification->id])
133+
// ->badge()
134+
// ->dir()
135+
// ->image()
136+
// ->lang()
137+
// ->renotify()
138+
// ->requireInteraction()
139+
// ->silent()
140+
// ->tag()
141+
// ->timestamp()
142+
// ->vibrate()
143+
// ->options(['TTL' => 1000, 'contentType' => 'application/json'])
144+
}
145+
}
146+
```
147+
110148
You can find the available options [here](https://github.com/web-push-libs/web-push-php#notifications-and-default-options).
111149

112150
### Save/Update Subscriptions

0 commit comments

Comments
 (0)