{"id":20696062,"url":"https://github.com/laravel-notification-channels/webpush","last_synced_at":"2025-04-29T14:20:03.786Z","repository":{"id":41259768,"uuid":"65542206","full_name":"laravel-notification-channels/webpush","owner":"laravel-notification-channels","description":"Webpush notifications channel for Laravel.","archived":false,"fork":false,"pushed_at":"2025-03-03T18:55:38.000Z","size":148,"stargazers_count":717,"open_issues_count":0,"forks_count":124,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-04-29T14:19:58.401Z","etag":null,"topics":["laravel","notifications","webpush"],"latest_commit_sha":null,"homepage":"http://laravel-notification-channels.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laravel-notification-channels.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-12T09:41:17.000Z","updated_at":"2025-04-28T21:15:04.000Z","dependencies_parsed_at":"2025-03-23T20:00:31.058Z","dependency_job_id":null,"html_url":"https://github.com/laravel-notification-channels/webpush","commit_stats":{"total_commits":120,"total_committers":33,"mean_commits":"3.6363636363636362","dds":0.525,"last_synced_commit":"b31f7d807d30c80e7391063291ebfe9683bb7de5"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Fwebpush","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Fwebpush/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Fwebpush/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Fwebpush/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laravel-notification-channels","download_url":"https://codeload.github.com/laravel-notification-channels/webpush/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251516953,"owners_count":21601912,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","notifications","webpush"],"created_at":"2024-11-17T00:12:24.398Z","updated_at":"2025-04-29T14:20:03.769Z","avatar_url":"https://github.com/laravel-notification-channels.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Web Push Notifications Channel for Laravel\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/webpush.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/webpush)\n![Build Status](https://github.com/laravel-notification-channels/webpush/workflows/tests/badge.svg)\n[![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/webpush.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/webpush)\n[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/webpush/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/webpush/?branch=master)\n[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/webpush.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/webpush)\n\nThis package makes it easy to send web push notifications with Laravel.\n\n## Installation\n\nYou can install the package via Composer:\n\n```bash\ncomposer require laravel-notification-channels/webpush\n```\n\nFirst, add the `NotificationChannels\\WebPush\\HasPushSubscriptions` trait to your `User` model:\n\n```php\nuse NotificationChannels\\WebPush\\HasPushSubscriptions;\n\nclass User extends Model\n{\n    use HasPushSubscriptions;\n}\n```\n\nNext, publish the migration with:\n\n```bash\nphp artisan vendor:publish --provider=\"NotificationChannels\\WebPush\\WebPushServiceProvider\" --tag=\"migrations\"\n```\n\nRun the migrate command to create the necessary table:\n\n```bash\nphp artisan migrate\n```\n\nYou can also publish the config file with:\n\n```bash\nphp artisan vendor:publish --provider=\"NotificationChannels\\WebPush\\WebPushServiceProvider\" --tag=\"config\"\n```\n\nGenerate the VAPID keys (required for browser authentication) with:\n\n```bash\nphp artisan webpush:vapid\n```\n\nThis 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).\n\n\u003e **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.\n\n__These keys must be safely stored and should not change.__\n\n## Usage\n\nNow you can use the channel in your `via()` method inside the notification and send a web push notification:\n\n```php\nuse Illuminate\\Notifications\\Notification;\nuse NotificationChannels\\WebPush\\WebPushMessage;\nuse NotificationChannels\\WebPush\\WebPushChannel;\n\nclass AccountApproved extends Notification\n{\n    public function via($notifiable)\n    {\n        return [WebPushChannel::class];\n    }\n\n    public function toWebPush($notifiable, $notification)\n    {\n        return (new WebPushMessage)\n            -\u003etitle('Approved!')\n            -\u003eicon('/approved-icon.png')\n            -\u003ebody('Your account was approved!')\n            -\u003eaction('View account', 'view_account')\n            -\u003eoptions(['TTL' =\u003e 1000]);\n            // -\u003edata(['id' =\u003e $notification-\u003eid])\n            // -\u003ebadge()\n            // -\u003edir()\n            // -\u003eimage()\n            // -\u003elang()\n            // -\u003erenotify()\n            // -\u003erequireInteraction()\n            // -\u003etag()\n            // -\u003evibrate()\n    }\n}\n```\n\nYou can find the available options [here](https://github.com/web-push-libs/web-push-php#notifications-and-default-options).\n\n### Save/Update Subscriptions\n\nTo save or update a subscription, use the `updatePushSubscription($endpoint, $key = null, $token = null, $contentEncoding = null)` method on your user:\n\n```php\n$user = \\App\\User::find(1);\n\n$user-\u003eupdatePushSubscription($endpoint, $key, $token, $contentEncoding);\n```\n\nThe `$key` and `$token` are optional and are used to encrypt your notifications. However, all major browsers require encryption when sending notifications.\n\nWhen 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.\n\n### Delete Subscriptions\n\nTo delete a subscription, use the `deletePushSubscription($endpoint)` method on your user:\n\n```php\n$user = \\App\\User::find(1);\n\n$user-\u003edeletePushSubscription($endpoint);\n```\n\n## Browser Compatibility\n\nSee the [Push API](https://caniuse.com/#feat=push-api) browser compatibility.\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Security\n\nIf you discover any security-related issues, please email themsaid@gmail.com instead of using the issue tracker.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Credits\n\n- [Cretu Eusebiu](https://github.com/cretueusebiu)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaravel-notification-channels%2Fwebpush","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaravel-notification-channels%2Fwebpush","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaravel-notification-channels%2Fwebpush/lists"}