PHPackages                             asacanell/push-notification - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. asacanell/push-notification

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

asacanell/push-notification
===========================

Laravel Package to send push notifications to Android and IOS devices. (GCM,FCM,APN)

5.5.0(1y ago)02.3k↓100%MITPHPPHP ^7.1.3|^8.0

Since Mar 2Pushed 1y agoCompare

[ Source](https://github.com/ASacanell/PushNotification)[ Packagist](https://packagist.org/packages/asacanell/push-notification)[ RSS](/packages/asacanell-push-notification/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (5)Used By (0)

PushNotification Package
========================

[](#pushnotification-package)

[![Build Status](https://camo.githubusercontent.com/1aee4f26cf241668962756efc8ff08e4919f1626bb6a47bc01a6d1aafb5fe54b/68747470733a2f2f6170692e7472617669732d63692e6f72672f4564756a75676f6e2f507573684e6f74696669636174696f6e2e737667)](https://api.travis-ci.org/Edujugon/PushNotification)[![Total Downloads](https://camo.githubusercontent.com/19af6725397ae8ce3bbb20eae949861cd4a19e29300908bff9541a5d9676dbbe/68747470733a2f2f706f7365722e707567782e6f72672f6564756a75676f6e2f707573682d6e6f74696669636174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/edujugon/push-notification)[![Latest Stable Version](https://camo.githubusercontent.com/3e8e0ae89fa1cba6a94fb621b06a7d97f58aeb67c0e27a784ffae303c5f527b3/68747470733a2f2f706f7365722e707567782e6f72672f6564756a75676f6e2f707573682d6e6f74696669636174696f6e2f762f737461626c65)](https://packagist.org/packages/edujugon/push-notification)[![License](https://camo.githubusercontent.com/ac7882b6ddb42be5456ca046ea1d21410701e8824cb1e062014bed5518009dc0/68747470733a2f2f706f7365722e707567782e6f72672f6564756a75676f6e2f707573682d6e6f74696669636174696f6e2f6c6963656e7365)](https://packagist.org/packages/edujugon/push-notification)

This is an easy to use package to send push notification.

#### Push Service Providers Available:

[](#push-service-providers-available)

- GCM
- FCM
- APN
- APN with .P8 key

Installation
------------

[](#installation)

### Laravel version below 5.8

[](#laravel-version-below-58)

type in console:

```
composer require "edujugon/push-notification:^v3.0.0"

```

### Laravel 5.8/6 and higher

[](#laravel-586-and-higher)

type in console:

```
composer require edujugon/push-notification

```

The package will automatically register its service provider.

Publish the package's configuration file to the application's own config directory

```
php artisan vendor:publish --provider="Edujugon\PushNotification\Providers\PushNotificationServiceProvider" --tag="config"

```

> Go to [laravel facade sample](https://github.com/edujugon/PushNotification#laravel-alias-facade) directly.

### Configuration

[](#configuration)

After publishing the configuration, you can find the Push service config in config/pushnotification.php

The default configuration parameters for **GCM** and **FCM** are :

- priority =&gt; normal
- dry\_run =&gt; false
- apiKey =&gt; Your ApiKey

You can dynamically update those values or adding new ones calling the method setConfig like so:

```
$push->setConfig([
    'priority' => 'high',
    'dry_run' => true,
    'time_to_live' => 3
]);
```

The default configuration parameters for **APN** are:

- `certificate => __DIR__ . '/iosCertificates/yourCertificate.pem'`
- `passPhrase => 'MyPassPhrase'`
- `passFile => __DIR__ . '/iosCertificates/yourKey.pem' //Optional`
- `dry_run => false`

The default configuration parameters for **APN P8** are:

- `key => __DIR__ . '/key.p8'`
- `keyId => 'MyKeyId'`
- `teamId => 'MyAppleTeamId'`
- `dry_run => false`

(Make sure to set `dry_run` to `true` if you're using development token, and `false` for production)

Also you can update those values and add more dynamically

```
$push->setConfig([
    'passPhrase' => 'NewPass',
    'custom' => 'MycustomValue',
    'dry_run' => true
]);
```

Even you may update the url of the Push Service dynamically like follows:

```
$push->setUrl('http://newPushServiceUrl.com');
```

> Not update the url unless it's really necessary.

You can specify the number of client-side attempts to APN before giving up. The default amount is 3 attempts. You can override this value by specifying `connection_attempts` in `setConfig()` assoc-array. Keep in mind the default number of requested attempts is 3.

If you prefer to retry indefinitely, set `connection_attempts` to zero.

```
$push->setConfig([
    'passPhrase' => 'NewPass',
    'custom' => 'MycustomValue',
    'connection_attempts' => 0,
    'dry_run' => true
]);

```

Usage
-----

[](#usage)

```
$push = new PushNotification;
```

By default it will use GCM as Push Service provider.

For APN Service:

```
$push = new PushNotification('apn');
```

```
$push = new PushNotification('apnp8');
```

For FCM Service:

```
$push = new PushNotification('fcm');
```

Now you may use any method that you need. Please see the API List.

API List
--------

[](#api-list)

- [setService](https://github.com/edujugon/PushNotification#setservice)
- [setMessage](https://github.com/edujugon/PushNotification#setmessage)
- [setDevicesToken](https://github.com/edujugon/PushNotification#setdevicestoken)
- [send](https://github.com/edujugon/PushNotification#send)
- [getFeedback](https://github.com/edujugon/PushNotification#getfeedback)
- [getUnregisteredDeviceTokens](https://github.com/edujugon/PushNotification#getunregistereddevicetokens)
- [setConfig](https://github.com/edujugon/PushNotification#setconfig)
- [setUrl](https://github.com/edujugon/PushNotification#seturl)

### Only for Gcm and Fcm

[](#only-for-gcm-and-fcm)

- [setApiKey](https://github.com/edujugon/PushNotification#setapikey)

### Only for Fcm

[](#only-for-fcm)

- [sendByTopic](https://github.com/edujugon/PushNotification#sendbytopic)

> Go to [Usage samples](https://github.com/edujugon/PushNotification#usage-samples) directly.

#### setService

[](#setservice)

`setService` method sets the push service to be used, which you pass the name through parameter as a string.

**Syntax**

```
object setService($name)
```

#### setMessage

[](#setmessage)

`setMessage` method sets the message parameters, which you pass the values through parameter as an array.

**Syntax**

```
object setMessage(array $data)
```

#### setApiKey

[](#setapikey)

> Only for gcm and fcm

`setApiKey` method sets the API Key of your App, which you pass the key through parameter as a string.

**Syntax**

```
object setApiKey($api_key)
```

#### setDevicesToken

[](#setdevicestoken)

`setDevicesToken` method sets the devices' tokens, which you pass the token through parameter as array or string if it was only one.

**Syntax**

```
object setDevicesToken($deviceTokens)
```

#### send

[](#send)

`send` method sends the notification.

**Syntax**

```
object send()
```

#### getFeedback

[](#getfeedback)

`getFeedback` method gets the notification response, which you may use it chaining it to `send` method or call it whenever after sending a notification.

**Syntax**

```
object getFeedback()
```

#### getUnregisteredDeviceTokens

[](#getunregistereddevicetokens)

`getUnregisteredDeviceTokens` method gets the devices' tokens that couldn't receive the notification because they aren't registered to the Push service provider. You may use it chaining it to `send` method or call it whenever after sending a notification.

**Syntax**

```
array getUnregisteredDeviceTokens()
```

#### setConfig

[](#setconfig)

`setConfig` method sets the Push service configuration, which you pass the name through parameter as an array.

**Syntax**

```
object setConfig(array $config)
```

#### setUrl

[](#seturl)

`setUrl` method sets the Push service url, which you pass the name through parameter as a string.

**Syntax**

```
object setUrl($url)
```

> Not update the url unless it's really necessary.

#### sendByTopic

[](#sendbytopic)

> Only for fcm

`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)

> If isCondition is true, $topic will be treated as an expression

**Syntax**

```
object sendByTopic($topic,$isCondition)
```

### Usage samples

[](#usage-samples)

> You can chain the methods.

GCM sample:

```
$push->setMessage([
        'notification' => [
                'title'=>'This is the title',
                'body'=>'This is the message',
                'sound' => 'default'
                ],
        'data' => [
                'extraPayLoad1' => 'value1',
                'extraPayLoad2' => 'value2'
                ]
        ])
        ->setApiKey('Server-API-Key')
        ->setDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...]);
```

APN sample:

```
$push->setMessage([
            'aps' => [
                'alert' => [
                    'title' => 'This is the title',
                    'body' => 'This is the body'
                ],
                'sound' => 'default',
                'badge' => 1

            ],
            'extraPayLoad' => [
                'custom' => 'My custom data',
            ]
        ])
    ->setDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...]);
```

or do it separately

```
$push->setMessage([
       'notification' => [
               'title'=>'This is the title',
               'body'=>'This is the message',
               'sound' => 'default'
               ],
       'data' => [
               'extraPayLoad1' => 'value1',
               'extraPayLoad2' => 'value2'
               ]
       ]);
$push->setApiKey('Server-API-Key');
$push->setDevicesToken(['deviceToken1'
    ,'deviceToken2',
    'deviceToken3'
]);
```

If you want send the notification to only 1 device, you may pass the value as string.

```
$push->setDevicesToken('deviceToken');
```

### Send the Notification

[](#send-the-notification)

Method send() can be also chained to the above methods.

```
$push->setMessage([
       'notification' => [
               'title'=>'This is the title',
               'body'=>'This is the message',
               'sound' => 'default'
               ],
       'data' => [
               'extraPayLoad1' => 'value1',
               'extraPayLoad2' => 'value2'
               ]
       ])
    ->setApiKey('Server-API-Key')
    ->setDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...])
    ->send();
```

### Send the Notification by Topic (**FCM** only)

[](#send-the-notification-by-topic-fcm-only)

```
$push = new PushNotification('fcm');
$response = $push->setMessage(['message'=>'Hello World'])
            ->setApiKey('YOUR-API-KEY')
            ->setConfig(['dry_run' => false])
            ->sendByTopic('dogs');
```

or with a condition:

```
$push = new PushNotification('fcm');
$response = $push->setMessage(['message'=>'Hello World'])
            ->setApiKey('YOUR-API-KEY')
            ->setConfig(['dry_run' => false])
            ->sendByTopic("'dogs' in topics || 'cats' in topics",true);
```

### Understanding Gcm and Fcm Message Payload

[](#understanding-gcm-and-fcm-message-payload)

#### Notification Message

[](#notification-message)

Add a `notification` key when setting the message in `setMessage` method. like follows:

```
$push->setMessage([
           'notification' => [
                   'title'=>'This is the title',
                   'body'=>'This is the message',
                   'sound' => 'default'
                   ]
           );
```

You may add some extra payload adding a `data` key when setting the message in `setMessage` method.

```
$push->setMessage([
           'notification' => [
                   'title'=>'This is the title',
                   'body'=>'This is the message',
                   'sound' => 'default'
                   ],
           'data' => [
                   'extraPayLoad1' => 'value1',
                   'extraPayLoad2' => 'value2'
                   ]
           ]);
```

#### Data Message

[](#data-message)

By default, this package sends the notification as Data Message. So no need to add a `data` key.

```
$push->setMessage([
           'title'=>'This is the title',
           'body'=>'This is the message',
           'myCustomVAlue' => 'value'
       ]);
```

The above example is like you were sending the following:

```
$push->setMessage([
           'data' => [
                   'title'=>'This is the title',
                  'body'=>'This is the message',
                  'myCustomVAlue' => 'value'
                   ]
           ]);
```

For 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)

### Getting the Notification Response

[](#getting-the-notification-response)

If you want to get the push service response, you can call the method `getFeedback`:

```
    $push->getFeedback();
```

Or again, chain it to the above methods:

```
    $push->setMessage(['body'=>'This is the message','title'=>'This is the title'])
                        ->setApiKey('Server-API-Key')
                        ->setDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...])
                        ->send()
                        ->getFeedback();
```

It will return an object with the response.

### APN Server Feedback and package Feedback

[](#apn-server-feedback-and-package-feedback)

Any time you send a notification, it will check if APN server has any feedback for your certificate. If so, the responses are merged to our feedback like below:

```
class stdClass#21 (4) {
  public $success =>
  int(0)
  public $failure =>
  int(1)
  public $tokenFailList =>
  array(1) {
    [0] =>
    string(64) "c55741656e6c3185f3474291aebb5cf878b8719288e52bf4c497292b320312c5"
  }
  public $apnsFeedback =>
  array(1) {
    [0] =>
    class stdClass#16 (3) {
      public $timestamp =>
      int(1478272639)
      public $length =>
      int(32)
      public $devtoken =>
      string(64) "c55741656e6c3185f3474291aebb5cf878b8719288e52bf4c497292b320312c5"
    }
  }
}
```

### Get Unregistered Devices tokens

[](#get-unregistered-devices-tokens)

After sending a notification, you may retrieve the list of unregistered tokens

```
$push->getUnregisteredDeviceTokens();
```

This 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.

### Laravel Alias Facade

[](#laravel-alias-facade)

After register the Alias Facade for this Package, you can use it like follows:

```
PushNotification::setService('fcm')
                        ->setMessage([
                             'notification' => [
                                     'title'=>'This is the title',
                                     'body'=>'This is the message',
                                     'sound' => 'default'
                                     ],
                             'data' => [
                                     'extraPayLoad1' => 'value1',
                                     'extraPayLoad2' => 'value2'
                                     ]
                             ])
                        ->setApiKey('Server-API-Key')
                        ->setDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...])
                        ->send()
                        ->getFeedback();
```

It would return the Push Feedback of the Notification sent.

### Notification channels

[](#notification-channels)

#### Formatting Push Notifications

[](#formatting-push-notifications)

If 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:

```
public function toApn($notifiable)
{
    return new PushMessage('Hello world');
}
```

#### Customizing The Title and Body

[](#customizing-the-title-and-body)

```
public function toApn($notifiable)
{
    return (new PushMessage)
        ->title('Hello world')
        ->body('...');
}
```

#### Customizing The Notification Sound

[](#customizing-the-notification-sound)

```
public function toApn($notifiable)
{
    return (new PushMessage)
        ->body('Hello world')
        ->sound('default');
}
```

#### Customizing The Badge Number

[](#customizing-the-badge-number)

```
public function toApn($notifiable)
{
  return (new PushMessage)
        ->body('Hello world')
        ->sound('default')
        ->badge(7);
}
```

#### Passing Service Config

[](#passing-service-config)

```
public function toApn($notifiable)
{
    return (new PushMessage)
        ->body('Hello world')
        ->config(['dry_run' => false]);
}
```

#### Add it to the notification channels

[](#add-it-to-the-notification-channels)

```
public function via($notifiable)
{
    return [ApnChannel::class];
}
```

> Don't forget the use statement at the top of the class

#### Routing Push Notifications

[](#routing-push-notifications)

Just define `routeNotificationForApn` and/or `routeNotificationForFcm`/`routeNotificationForGcm` methods on the entity

```
/**
 * Route notifications for the Apn channel.
 *
 * @return string|array
 */
public function routeNotificationForApn()
{
    return $this->ios_push_token;
}
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~276 days

Total

3

Last Release

613d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/558eecccfc300c0912011ab110a00704300d30a75b6a9a3b9ab832dac7ab8de8?d=identicon)[ASacanell](/maintainers/ASacanell)

---

Top Contributors

[![Edujugon](https://avatars.githubusercontent.com/u/4853751?v=4)](https://github.com/Edujugon "Edujugon (150 commits)")[![jenky](https://avatars.githubusercontent.com/u/1808758?v=4)](https://github.com/jenky "jenky (12 commits)")[![pultho](https://avatars.githubusercontent.com/u/18327485?v=4)](https://github.com/pultho "pultho (7 commits)")[![klimov-paul](https://avatars.githubusercontent.com/u/1482054?v=4)](https://github.com/klimov-paul "klimov-paul (7 commits)")[![alvibd](https://avatars.githubusercontent.com/u/20942401?v=4)](https://github.com/alvibd "alvibd (6 commits)")[![sevrugin](https://avatars.githubusercontent.com/u/4169835?v=4)](https://github.com/sevrugin "sevrugin (5 commits)")[![ASacanell](https://avatars.githubusercontent.com/u/11868896?v=4)](https://github.com/ASacanell "ASacanell (5 commits)")[![xHeinrich](https://avatars.githubusercontent.com/u/7674587?v=4)](https://github.com/xHeinrich "xHeinrich (2 commits)")[![eliyas5044](https://avatars.githubusercontent.com/u/13916443?v=4)](https://github.com/eliyas5044 "eliyas5044 (2 commits)")[![jeroen-van-dijk](https://avatars.githubusercontent.com/u/10112015?v=4)](https://github.com/jeroen-van-dijk "jeroen-van-dijk (2 commits)")[![jkirow](https://avatars.githubusercontent.com/u/4324810?v=4)](https://github.com/jkirow "jkirow (2 commits)")[![MatanYadaev](https://avatars.githubusercontent.com/u/13586343?v=4)](https://github.com/MatanYadaev "MatanYadaev (2 commits)")[![dunice](https://avatars.githubusercontent.com/u/1914090?v=4)](https://github.com/dunice "dunice (2 commits)")[![Varin6](https://avatars.githubusercontent.com/u/21034827?v=4)](https://github.com/Varin6 "Varin6 (1 commits)")[![pascalvgemert](https://avatars.githubusercontent.com/u/1567379?v=4)](https://github.com/pascalvgemert "pascalvgemert (1 commits)")[![csabex94](https://avatars.githubusercontent.com/u/17952851?v=4)](https://github.com/csabex94 "csabex94 (1 commits)")[![ammardev](https://avatars.githubusercontent.com/u/16087389?v=4)](https://github.com/ammardev "ammardev (1 commits)")[![cs-couture](https://avatars.githubusercontent.com/u/35463502?v=4)](https://github.com/cs-couture "cs-couture (1 commits)")[![ghecho](https://avatars.githubusercontent.com/u/952873?v=4)](https://github.com/ghecho "ghecho (1 commits)")

---

Tags

laravelpushnotificationgcmFCMapnpriorityhigh

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/asacanell-push-notification/health.svg)

```
[![Health](https://phpackages.com/badges/asacanell-push-notification/health.svg)](https://phpackages.com/packages/asacanell-push-notification)
```

###  Alternatives

[edujugon/push-notification

Laravel Package to send push notifications to Android and IOS devices. (GCM,FCM,APN)

4891.4M1](/packages/edujugon-push-notification)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
