You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-24Lines changed: 24 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Web push notifications channel for Laravel
1
+
# Web Push Notifications Channel for Laravel
2
2
3
3
[](https://packagist.org/packages/laravel-notification-channels/webpush)
Generate the VAPID keys (required for browser authentication) with:
49
49
50
-
```bash
50
+
```bash
51
51
php artisan webpush:vapid
52
52
```
53
53
54
-
This command will set `VAPID_PUBLIC_KEY` and `VAPID_PRIVATE_KEY`in your `.env` file.
54
+
This command will set `VAPID_PUBLIC_KEY` and `VAPID_PRIVATE_KEY`in your `.env` file. You need the `VAPID_PUBLIC_KEY` as `applicationServerKey` when using the [Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API).
55
55
56
-
> Note: if targeting Safari or iOS after 2023, you will need to include the `VAPID_SUBJECT` variable as well or Apple will return a `BadJwtToken` error.
56
+
> **Note:** If targeting Safari or iOS after 2023, you will need to include the `VAPID_SUBJECT` variable as well, or Apple will return a `BadJwtToken` error.
57
57
58
58
__These keys must be safely stored and should not change.__
59
59
60
-
If you still want support for [Google Cloud Messaging](https://console.cloud.google.com), set the `GCM_KEY` and `GCM_SENDER_ID` in your `.env` file.
61
-
62
60
## Usage
63
61
64
-
Now you can use the channel in your `via()` method inside the notification as well as send a web push notification:
62
+
Now you can use the channel in your `via()` method inside the notification and send a web push notification:
65
63
66
-
```php
64
+
```php
67
65
use Illuminate\Notifications\Notification;
68
66
use NotificationChannels\WebPush\WebPushMessage;
69
67
use NotificationChannels\WebPush\WebPushChannel;
@@ -100,21 +98,23 @@ You can find the available options [here](https://github.com/web-push-libs/web-p
100
98
101
99
### Save/Update Subscriptions
102
100
103
-
To save or update a subscription use the `updatePushSubscription($endpoint, $key = null, $token = null, $contentEncoding = null)` method on your user:
101
+
To save or update a subscription, use the `updatePushSubscription($endpoint, $key = null, $token = null, $contentEncoding = null)` method on your user:
The `$key` and `$token` are optional and are used to encrypt your notifications. Only encrypted notifications can have a payload.
109
+
The `$key` and `$token` are optional and are used to encrypt your notifications. However, all major browsers require encryption when sending notifications.
110
+
111
+
When using the [Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API), `$key` is the value of the `getKey('p256dh')` method, and `$token` is the value of the `getKey('auth')` method of the `PushSubscription` interface.
112
112
113
113
### Delete Subscriptions
114
114
115
-
To delete a subscription use the `deletePushSubscription($endpoint)` method on your user:
115
+
To delete a subscription, use the `deletePushSubscription($endpoint)` method on your user:
116
116
117
-
```php
117
+
```php
118
118
$user = \App\User::find(1);
119
119
120
120
$user->deletePushSubscription($endpoint);
@@ -130,13 +130,13 @@ Please see [CHANGELOG](CHANGELOG.md) for more information about what has changed
130
130
131
131
## Testing
132
132
133
-
```bash
134
-
$ composer test
133
+
```bash
134
+
composer test
135
135
```
136
136
137
137
## Security
138
138
139
-
If you discover any securityrelated issues, please email themsaid@gmail.com instead of using the issue tracker.
139
+
If you discover any security-related issues, please email themsaid@gmail.com instead of using the issue tracker.
0 commit comments