{"id":16458184,"url":"https://github.com/edujugon/pushnotification","last_synced_at":"2025-05-15T03:08:45.002Z","repository":{"id":9365589,"uuid":"61828001","full_name":"Edujugon/PushNotification","owner":"Edujugon","description":"PHP and Laravel Package to send push notifications to Android and IOS devices.","archived":false,"fork":false,"pushed_at":"2024-06-20T13:21:11.000Z","size":173,"stargazers_count":484,"open_issues_count":43,"forks_count":160,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-05-15T03:08:32.488Z","etag":null,"topics":["apns","fcm","gcm","laravel","laravel-notification-channels","notification-channel","push-notifications","pushnotification"],"latest_commit_sha":null,"homepage":"","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/Edujugon.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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-06-23T18:34:01.000Z","updated_at":"2025-04-09T12:16:56.000Z","dependencies_parsed_at":"2023-12-31T04:01:05.162Z","dependency_job_id":"29dd416d-e824-4213-bf41-cc7ecb2a8528","html_url":"https://github.com/Edujugon/PushNotification","commit_stats":{"total_commits":172,"total_committers":23,"mean_commits":7.478260869565218,"dds":0.7674418604651163,"last_synced_commit":"bac0739b9c4195b710de1a31c151f9ebe9bb449d"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edujugon%2FPushNotification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edujugon%2FPushNotification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edujugon%2FPushNotification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edujugon%2FPushNotification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Edujugon","download_url":"https://codeload.github.com/Edujugon/PushNotification/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254264771,"owners_count":22041794,"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":["apns","fcm","gcm","laravel","laravel-notification-channels","notification-channel","push-notifications","pushnotification"],"created_at":"2024-10-11T10:44:30.937Z","updated_at":"2025-05-15T03:08:39.970Z","avatar_url":"https://github.com/Edujugon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PushNotification Package\n\n[![Build Status](https://api.travis-ci.org/Edujugon/PushNotification.svg)](https://api.travis-ci.org/Edujugon/PushNotification)\n[![Total Downloads](https://poser.pugx.org/edujugon/push-notification/downloads)](https://packagist.org/packages/edujugon/push-notification)\n[![Latest Stable Version](https://poser.pugx.org/edujugon/push-notification/v/stable)](https://packagist.org/packages/edujugon/push-notification)\n[![License](https://poser.pugx.org/edujugon/push-notification/license)](https://packagist.org/packages/edujugon/push-notification)\n\nThis is an easy to use package to send push notification.\n\n#### Push Service Providers Available:\n\n* GCM\n* FCM\n* APN\n\n## Installation\n\n### Laravel version below 5.8\n\ntype in console:\n\n```\ncomposer require \"edujugon/push-notification:^v3.0.0\"\n```\n\n### Laravel 5.8/6 and higher\n\ntype in console:\n\n```\ncomposer require edujugon/push-notification\n```\n\nThe package will automatically register its service provider.\n\nPublish the package's configuration file to the application's own config directory\n```\nphp artisan vendor:publish --provider=\"Edujugon\\PushNotification\\Providers\\PushNotificationServiceProvider\" --tag=\"config\"\n```\n\n\u003e Go to [laravel facade sample](https://github.com/edujugon/PushNotification#laravel-alias-facade) directly.\n\n### Configuration\n\nAfter publishing the configuration, you can find the Push service config in config/pushnotification.php\n\nThe default configuration parameters for **GCM** and **FCM** are :\n\n*   priority =\u003e normal\n*   dry_run =\u003e false\n*   apiKey =\u003e Your ApiKey\n\nYou can dynamically update those values or adding new ones calling the method setConfig like so:\n```php\n$push-\u003esetConfig([\n    'priority' =\u003e 'high',\n    'dry_run' =\u003e true,\n    'time_to_live' =\u003e 3\n]);\n```\n\n\nThe default configuration parameters for **APN** are:\n\n*   ```certificate =\u003e __DIR__ . '/iosCertificates/yourCertificate.pem'```\n*   ```passPhrase =\u003e 'MyPassPhrase'```\n*   ```passFile =\u003e __DIR__ . '/iosCertificates/yourKey.pem' //Optional```\n*   ```dry_run =\u003e false```\n\n(Make sure to set `dry_run` to `true` if you're using development *.pem certificate, and `false` for production)\n\nAlso you can update those values and add more dynamically\n```php\n$push-\u003esetConfig([\n    'passPhrase' =\u003e 'NewPass',\n    'custom' =\u003e 'MycustomValue',\n    'dry_run' =\u003e true\n]);\n```\n\nEven you may update the url of the Push Service dynamically like follows:\n```php\n$push-\u003esetUrl('http://newPushServiceUrl.com');\n```\n\n\u003e Not update the url unless it's really necessary.\n\nYou can specify the number of client-side attempts to APN before giving\nup.  The default amount is 3 attempts.  You can override this value by\nspecifying `connection_attempts` in `setConfig()` assoc-array.  Keep in\nmind the default number of requested attempts is 3.\n\nIf you prefer to retry indefinitely, set `connection_attempts` to zero.\n\n    $push-\u003esetConfig([\n        'passPhrase' =\u003e 'NewPass',\n        'custom' =\u003e 'MycustomValue',\n        'connection_attempts' =\u003e 0,\n        'dry_run' =\u003e true\n    ]);\n\n\n## Usage\n```php\n$push = new PushNotification;\n```\n\nBy default it will use GCM as Push Service provider.\n\nFor APN Service:\n```php\n$push = new PushNotification('apn');\n```\n\nFor FCM Service:\n```php\n$push = new PushNotification('fcm');\n```\n\nNow you may use any method that you need. Please see the API List.\n\n\n## API List\n\n- [setService](https://github.com/edujugon/PushNotification#setservice)\n- [setMessage](https://github.com/edujugon/PushNotification#setmessage)\n- [setDevicesToken](https://github.com/edujugon/PushNotification#setdevicestoken)\n- [send](https://github.com/edujugon/PushNotification#send)\n- [getFeedback](https://github.com/edujugon/PushNotification#getfeedback)\n- [getUnregisteredDeviceTokens](https://github.com/edujugon/PushNotification#getunregistereddevicetokens)\n- [setConfig](https://github.com/edujugon/PushNotification#setconfig)\n- [setUrl](https://github.com/edujugon/PushNotification#seturl)\n\n### Only for Gcm and Fcm\n\n- [setApiKey](https://github.com/edujugon/PushNotification#setapikey)\n\n### Only for Fcm\n\n- [sendByTopic](https://github.com/edujugon/PushNotification#sendbytopic)\n\n\u003e Go to [Usage samples](https://github.com/edujugon/PushNotification#usage-samples) directly.\n\n#### setService\n\n`setService` method sets the push service to be used, which you pass the name through parameter as a string.\n\n**Syntax**\n\n```php\nobject setService($name)\n```\n\n#### setMessage\n\n`setMessage` method sets the message parameters, which you pass the values through parameter as an array.\n\n**Syntax**\n\n```php\nobject setMessage(array $data)\n```\n\n#### setApiKey\n\n\u003e Only for gcm and fcm\n\n`setApiKey` method sets the API Key of your App, which you pass the key through parameter as a string.\n\n**Syntax**\n\n```php\nobject setApiKey($api_key)\n```\n\n#### setDevicesToken\n\n`setDevicesToken` method sets the devices' tokens, which you pass the token through parameter as array or string if it was only one.\n\n**Syntax**\n\n```php\nobject setDevicesToken($deviceTokens)\n```\n\n#### send\n\n`send` method sends the notification.\n\n**Syntax**\n\n```php\nobject send()\n```\n\n#### getFeedback\n\n`getFeedback` method gets the notification response, which you may use it chaining it to `send` method or call it whenever after sending a notification.\n\n**Syntax**\n\n```php\nobject getFeedback()\n```\n\n#### getUnregisteredDeviceTokens\n\n`getUnregisteredDeviceTokens` method gets the devices' tokens that couldn't receive the notification because they aren't registered to the Push service provider.\nYou may use it chaining it to `send` method or call it whenever after sending a notification.\n\n**Syntax**\n\n```php\narray getUnregisteredDeviceTokens()\n```\n\n#### setConfig\n\n`setConfig` method sets the Push service configuration, which you pass the name through parameter as an array.\n\n**Syntax**\n\n```php\nobject setConfig(array $config)\n```\n\n#### setUrl\n\n`setUrl` method sets the Push service url, which you pass the name through parameter as a string.\n\n**Syntax**\n\n```php\nobject setUrl($url)\n```\n\u003e Not update the url unless it's really necessary.\n\n#### sendByTopic\n\n\u003e Only for fcm\n\n`sendBytopic` method sends a message by topic. It also accepts the topic condition. more details [here](https://firebase.google.com/docs/cloud-messaging/android/topic-messaging)\n\u003eIf isCondition is true, $topic will be treated as an expression\n\n**Syntax**\n\n```php\nobject sendByTopic($topic,$isCondition)\n```\n\n### Usage samples\n\n\u003eYou can chain the methods.\n\nGCM sample:\n\n```php\n$push-\u003esetMessage([\n        'notification' =\u003e [\n                'title'=\u003e'This is the title',\n                'body'=\u003e'This is the message',\n                'sound' =\u003e 'default'\n                ],\n        'data' =\u003e [\n                'extraPayLoad1' =\u003e 'value1',\n                'extraPayLoad2' =\u003e 'value2'\n                ]\n        ])\n        -\u003esetApiKey('Server-API-Key')\n        -\u003esetDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...]);\n```\n\nAPN sample:\n```php\n$push-\u003esetMessage([\n            'aps' =\u003e [\n                'alert' =\u003e [\n                    'title' =\u003e 'This is the title',\n                    'body' =\u003e 'This is the body'\n                ],\n                'sound' =\u003e 'default',\n                'badge' =\u003e 1\n\n            ],\n            'extraPayLoad' =\u003e [\n                'custom' =\u003e 'My custom data',\n            ]\n        ])\n    -\u003esetDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...]);\n```\nor do it separately\n```php\n$push-\u003esetMessage([\n       'notification' =\u003e [\n               'title'=\u003e'This is the title',\n               'body'=\u003e'This is the message',\n               'sound' =\u003e 'default'\n               ],\n       'data' =\u003e [\n               'extraPayLoad1' =\u003e 'value1',\n               'extraPayLoad2' =\u003e 'value2'\n               ]\n       ]);\n$push-\u003esetApiKey('Server-API-Key');\n$push-\u003esetDevicesToken(['deviceToken1'\n    ,'deviceToken2',\n    'deviceToken3'\n]);\n```\nIf you want send the notification to only 1 device, you may pass the value as string.\n```php\n$push-\u003esetDevicesToken('deviceToken');\n```\n\n### Send the Notification\n\nMethod send() can be also chained to the above methods.\n```php\n$push-\u003esetMessage([\n       'notification' =\u003e [\n               'title'=\u003e'This is the title',\n               'body'=\u003e'This is the message',\n               'sound' =\u003e 'default'\n               ],\n       'data' =\u003e [\n               'extraPayLoad1' =\u003e 'value1',\n               'extraPayLoad2' =\u003e 'value2'\n               ]\n       ])\n    -\u003esetApiKey('Server-API-Key')\n    -\u003esetDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...])\n    -\u003esend();\n```\n\n### Send the Notification by Topic (**FCM** only)\n\n```php\n$push = new PushNotification('fcm');\n$response = $push-\u003esetMessage(['message'=\u003e'Hello World'])\n            -\u003esetApiKey('YOUR-API-KEY')\n            -\u003esetConfig(['dry_run' =\u003e false])\n            -\u003esendByTopic('dogs');\n```\n\nor with a condition:\n```php\n$push = new PushNotification('fcm');\n$response = $push-\u003esetMessage(['message'=\u003e'Hello World'])\n            -\u003esetApiKey('YOUR-API-KEY')\n            -\u003esetConfig(['dry_run' =\u003e false])\n            -\u003esendByTopic(\"'dogs' in topics || 'cats' in topics\",true);\n```\n\n### Understanding Gcm and Fcm Message Payload\n\n#### Notification Message\n\nAdd a `notification` key when setting the message in `setMessage` method. like follows:\n\n```php\n$push-\u003esetMessage([\n           'notification' =\u003e [\n                   'title'=\u003e'This is the title',\n                   'body'=\u003e'This is the message',\n                   'sound' =\u003e 'default'\n                   ]\n           );\n```\n\nYou may add some extra payload adding a `data` key when setting the message in `setMessage` method.\n\n```php\n$push-\u003esetMessage([\n           'notification' =\u003e [\n                   'title'=\u003e'This is the title',\n                   'body'=\u003e'This is the message',\n                   'sound' =\u003e 'default'\n                   ],\n           'data' =\u003e [\n                   'extraPayLoad1' =\u003e 'value1',\n                   'extraPayLoad2' =\u003e 'value2'\n                   ]\n           ]);\n```\n\n#### Data Message\n\nBy default, this package sends the notification as Data Message. So no need to add a `data` key.\n\n```php\n$push-\u003esetMessage([\n           'title'=\u003e'This is the title',\n           'body'=\u003e'This is the message',\n           'myCustomVAlue' =\u003e 'value'\n       ]);\n```\n\nThe above example is like you were sending the following:\n\n```php\n$push-\u003esetMessage([\n           'data' =\u003e [\n                   'title'=\u003e'This is the title',\n                  'body'=\u003e'This is the message',\n                  'myCustomVAlue' =\u003e 'value'\n                   ]\n           ]);\n```\n\nFor more details, have a look at [gcm/fcm notification paypload support](https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support) and [the concept options](https://firebase.google.com/docs/cloud-messaging/concept-options)\n\n### Getting the Notification Response\n\nIf you want to get the push service response, you can call the method `getFeedback`:\n```php\n    $push-\u003egetFeedback();\n```\n\nOr again, chain it to the above methods:\n```php\n    $push-\u003esetMessage(['body'=\u003e'This is the message','title'=\u003e'This is the title'])\n                        -\u003esetApiKey('Server-API-Key')\n                        -\u003esetDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...])\n                        -\u003esend()\n                        -\u003egetFeedback();\n```\n\nIt will return an object with the response.\n\n### APN Server Feedback and package Feedback\n\nAny time you send a notification, it will check if APN server has any feedback for your certificate.\nIf so, the responses are merged to our feedback like below:\n\n```php\nclass stdClass#21 (4) {\n  public $success =\u003e\n  int(0)\n  public $failure =\u003e\n  int(1)\n  public $tokenFailList =\u003e\n  array(1) {\n    [0] =\u003e\n    string(64) \"c55741656e6c3185f3474291aebb5cf878b8719288e52bf4c497292b320312c5\"\n  }\n  public $apnsFeedback =\u003e\n  array(1) {\n    [0] =\u003e\n    class stdClass#16 (3) {\n      public $timestamp =\u003e\n      int(1478272639)\n      public $length =\u003e\n      int(32)\n      public $devtoken =\u003e\n      string(64) \"c55741656e6c3185f3474291aebb5cf878b8719288e52bf4c497292b320312c5\"\n    }\n  }\n}\n\n```\n\n### Get Unregistered Devices tokens\n\nAfter sending a notification, you may retrieve the list of unregistered tokens\n```php\n$push-\u003egetUnregisteredDeviceTokens();\n```\n\nThis method returns an array of unregistered tokens from the Push service provider. If there isn't any unregistered token, it will return an empty array.\n\n### Laravel Alias Facade\n\nAfter register the Alias Facade for this Package, you can use it like follows:\n```php\nPushNotification::setService('fcm')\n                        -\u003esetMessage([\n                             'notification' =\u003e [\n                                     'title'=\u003e'This is the title',\n                                     'body'=\u003e'This is the message',\n                                     'sound' =\u003e 'default'\n                                     ],\n                             'data' =\u003e [\n                                     'extraPayLoad1' =\u003e 'value1',\n                                     'extraPayLoad2' =\u003e 'value2'\n                                     ]\n                             ])\n                        -\u003esetApiKey('Server-API-Key')\n                        -\u003esetDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...])\n                        -\u003esend()\n                        -\u003egetFeedback();\n```\n\nIt would return the Push Feedback of the Notification sent.\n\n### Notification channels\n\n#### Formatting Push Notifications\nIf a notification supports being sent as an push message, you should define  `toApn` and/or `toFcm`/`toGcm` methods on the notification class. This method will receive a `$notifiable` entity and should return a  `Edujugon\\PushNotification\\Messages\\PushMessage` instance:\n\n```php\npublic function toApn($notifiable)\n{\n    return new PushMessage('Hello world');\n}\n```\n\n#### Customizing The Title and Body\n```php\npublic function toApn($notifiable)\n{\n    return (new PushMessage)\n        -\u003etitle('Hello world')\n        -\u003ebody('...');\n}\n```\n\n#### Customizing The Notification Sound\n```php\npublic function toApn($notifiable)\n{\n    return (new PushMessage)\n        -\u003ebody('Hello world')\n        -\u003esound('default');\n}\n```\n\n#### Customizing The Badge Number\n```php\npublic function toApn($notifiable)\n{\n  return (new PushMessage)\n        -\u003ebody('Hello world')\n        -\u003esound('default')\n        -\u003ebadge(7);\n}\n```\n\n#### Passing Service Config\n```php\npublic function toApn($notifiable)\n{\n    return (new PushMessage)\n        -\u003ebody('Hello world')\n        -\u003econfig(['dry_run' =\u003e false]);\n}\n```\n\n#### Add it to the notification channels\n```php\npublic function via($notifiable)\n{\n    return [ApnChannel::class];\n}\n```\n\u003eDon't forget the use statement at the top of the class\n\n#### Routing Push Notifications\nJust define `routeNotificationForApn` and/or `routeNotificationForFcm`/`routeNotificationForGcm` methods on the entity\n```php\n/**\n * Route notifications for the Apn channel.\n *\n * @return string|array\n */\npublic function routeNotificationForApn()\n{\n    return $this-\u003eios_push_token;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedujugon%2Fpushnotification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedujugon%2Fpushnotification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedujugon%2Fpushnotification/lists"}