PHPackages                             kobir/larapush-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. kobir/larapush-notification

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

kobir/larapush-notification
===========================

Laravel package to send push notification to mobile devices (android, ios) using fcm http v1

v1.0.1(1y ago)319MITPHPPHP ^7.2|^7.3|^7.4|^8.0|^8.1|^8.2

Since Oct 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/kobirbd93/LaraPushNotification)[ Packagist](https://packagist.org/packages/kobir/larapush-notification)[ RSS](/packages/kobir-larapush-notification/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

Laravel Push Notification
=========================

[](#laravel-push-notification)

Simple Laravel package for sending push notification to mobile devices (android, ios) using fcm http v1.

### Requirements

[](#requirements)

- php version ^7.2 or higher
- Google API Client Library ^2.14.0 or higher
- Laravel version ^6.0 or higher

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

[](#installation)

Use composer to download and install the package and its dependencies.

```
composer require kobir/larapush-notification
```

if you are facing dependency version conflict related issues please run

```
composer require kobir/larapush-notification -W
```

The package will automatically register its service provider.

To publish the package's configuration file run the following command

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

### Configuration

[](#configuration)

After publishing the configuration, you can find the 'larapushnotification.php' as well as 'fcmCertificates' empty directory into the config folder.

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

- `'priority' => 'normal'`,
- `'certificate' => __DIR__ . '/fcmCertificates/fcm-admin-sdk.json',`
- `'dry_run' => false,`
- `'firebase_project_id' => 'FIREBASE_PROJECT_ID',`
- `'token_cache_time' => 3500, //in seconds & must be  [],`

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

```
$push->setConfig([
    'priority' => 'high',
    'firebase_project_id' => 'my-project-id',
    'certificate' => 'path/to/fcm-admin-sdk.json'
    'token_cache_time' => 3000
]);
```

To generate a credentials fcm-admin-sdk json file for your service account:

- In the Firebase console, open **Settings** &gt; [Service Accounts](https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk).
- Click **Generate New Private Key**, then confirm by clicking **Generate Key**.
- Securely store the JSON file containing the key.

Usage
-----

[](#usage)

To instantiate the Push Notification class

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

By default it will use **fcm** as Push Service provider or you can pass service name if you want as like...

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

Now you may use any method that you need. Please see the all methods list.

#### setNotification

[](#setnotification)

`setNotification` method use to set the notification basic parameters, which you pass the values through parameter as an array.

**Syntax**

```
object setNotification(array $data)
```

#### setData

[](#setdata)

`setData` method use to set the additional message parameters like id, type sound click\_action etc.., which you pass the values through parameter as an array.

**Syntax**

```
object setData(array $data)
```

#### setProjectId

[](#setprojectid)

`setProjectId` method use to set the Firebase Project ID of your App as a string.

**Syntax**

```
object setProjectId($projectId)
```

#### setJsonCredential

[](#setjsoncredential)

`setJsonCredential` method use to set the path of credentials json file of your App.

**Syntax**

```
object setJsonCredential($filePath)
```

#### 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 url through parameter as a string.

**Syntax**

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

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

#### setDevicesToken

[](#setdevicestoken)

`setDevicesToken` method use to set the devices' tokens, which you pass the token through parameter either array for multiple tokens or string if single token.

**Syntax**

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

#### send

[](#send)

`send` method is responsible for sending the push notification.

**Syntax**

```
object send()
```

#### getFeedback

[](#getfeedback)

`getFeedback` method return the full notification response after sending a notification.

**Syntax**

```
object getFeedback()
```

#### getFailedDeviceTokens

[](#getfaileddevicetokens)

`getFailedDeviceTokens` method return the all devices' tokens that couldn't receive the notification or failed. Further you can make logic to your backend code for that device tokens.

**Syntax**

```
array getFailedDeviceTokens()
```

#### sendByTopic

[](#sendbytopic)

`sendByTopic` method use to send notification 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)
```

#### addDeviceTokenToTopic

[](#adddevicetokentotopic)

`addDeviceTokenToTopic` method use to add device into a topic. To add a new topic you need a unique topic name &amp; all devices would you want to add this topic.

**Syntax**

```
object addDeviceTokenToTopic(string $topic)
```

#### removeDeviceTokenFromTopic

[](#removedevicetokenfromtopic)

`removeDeviceTokenFromTopic` method use to remove devices from a topic.

**Syntax**

```
object removeDeviceTokenFromTopic(string $topic)
```

#### getTopicInfo

[](#gettopicinfo)

`getTopicInfo` method use to get all topics name associate with the provided device token.

**Syntax**

```
object getTopicInfo(string $deviceToken)
```

#### setTopicAddUrl

[](#settopicaddurl)

`setTopicAddUrl` method sets the topic add url, which you pass the url through parameter as a string.

**Syntax**

```
object setTopicAddUrl($url)
```

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

#### setTopicRemoveUrl

[](#settopicremoveurl)

`setTopicRemoveUrl` method sets the topic remove url, which you pass the url through parameter as a string.

**Syntax**

```
object setTopicRemoveUrl($url)
```

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

#### setTopicInfoUrl

[](#settopicinfourl)

`setTopicInfoUrl` method sets the topic info url, which you pass the url through parameter as a string.

**Syntax**

```
object setTopicInfoUrl($url)
```

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

### Usage samples

[](#usage-samples)

```
$push = new PushNotification();
/***
 * (string) title
 * (string) body
 * (string) image, optional field image size must be less than 1mb
*/
$push->setNotification([
        'title' => (string) 'Title goes here',
        'body' => (string) 'Body text goes here',
        'image' => (string) 'image-url', //optional,
        ])
        ->setDevicesToken(['deviceToken1', 'deviceToken2', ...])
        ->send();
```

This is the basic data-set for notification. Here **send()** method used for sending push notification.

### Additional Payload

[](#additional-payload)

You can also pass the additional payload data by using **setData()** method

```
/***
 * (string) id, if haven't id place '0'
*/
$feedback = $push->setNotification([
                    'title' => (string) 'Title goes here',
                    'body' => (string) 'Body text goes here',
                    'image' => (string) 'image-url', //optional
                    ])
                    ->setData([
                    'id' => (string) 'dynamic_id',
                    'type' => 'OFFER',
                    'sound' => 'default',
                    'click_action' => 'NOTIFICATION_CLICK',
                    ])
                    ->setDevicesToken(['deviceToken1', 'deviceToken2', ...])
                    ->send()
                    ->getFeedback();
```

### Get Notification Feedback

[](#get-notification-feedback)

```
$feedback = $push->setNotification([
                'title' => (string) 'Title goes here',
                'body' => (string) 'Body text goes here',
                'image' => (string) 'image-url', //optional
                ])
                ->setDevicesToken(['deviceToken1', 'deviceToken2', ...])
                ->send()
                ->getFeedback();
```

If you want get the failed device tokens use **getFailedDeviceTokens()** method as ...

```
$failedTokens = $push->setNotification([
                    'title' => (string) 'Title goes here',
                    'body' => (string) 'Body text goes here',
                    'image' => (string) 'image-url', //optional
                    ])
                    ->setDevicesToken(['deviceToken1', 'deviceToken2', ...])
                    ->send()
                    ->getFailedDeviceTokens();
```

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

```
$feedback = $push->setNotification([
                'title' => (string) 'Title goes here',
                'body' => (string) 'Body text goes here',
                'image' => (string) 'image-url', //optional
                ])
                ->setDevicesToken('deviceToken')
                ->send()
                ->getFeedback();
```

### Send Notification by Topic

[](#send-notification-by-topic)

```
/***
 * (string) topic, name like 'foo', 'bar'
*/
$feedback = $push->setNotification([
                'title' => (string) 'Title goes here',
                'body' => (string) 'Body text goes here',
                'image' => (string) 'image-url', //optional
                ])
                ->sendByTopic('bar')
                ->getFeedback();
```

or with using a condition:

```
/***
 * you must have pass the additional parameter as 'true'
*/
$feedback = $push->setNotification([
                'title' => (string) 'Title goes here',
                'body' => (string) 'Body text goes here',
                'image' => (string) 'image-url', //optional
                ])
                ->sendByTopic("'foo' in topics || 'bar' in topics", true)
                ->getFeedback();
```

### Add Device Tokens into Topic

[](#add-device-tokens-into-topic)

```
$response = $push->setDevicesToken(['deviceToken1', 'deviceToken2', ...])
                ->addDeviceTokenToTopic('foo');
```

### Remove Device Tokens from Topic

[](#remove-device-tokens-from-topic)

```
$response = $push->setDevicesToken(['deviceToken1', 'deviceToken2', ...])
                ->removeDeviceTokenFromTopic('bar');
```

### Get Topic Information

[](#get-topic-information)

If you want to get how many topic associated with a device token then call this **getTopicInfo()** method with device\_token parameter.

```
$response = $push->getTopicInfo('deviceToken1');

//successful response will be like
{
    "applicationVersion": "19",
    "application": "com.iid.example",
    "authorizedEntity": "123456782354",
    "platform": "ANDROID",
    "rel": {
        "topics": {
            "cats": {
                "addDate": "2024-10-20"
            },
            "dogs": {
                "addDate": "2024-10-20"
            }
        }
    }
}
```

### Contribution

[](#contribution)

#### Submitting issues and pull requests for bugs or new feature(s) requests are always welcome.

[](#submitting-issues-and-pull-requests-for-bugs-or-new-features-requests-are-always-welcome)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~2 days

Total

3

Last Release

560d ago

PHP version history (2 changes)v1.0.0-alphaPHP ^7.2.5|^7.4|^8.0

v1.0.0PHP ^7.2|^7.3|^7.4|^8.0|^8.1|^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/5a1f60211a66c0c77b4b9ef3928ae596d3559d6bb4dede862a965757a18019e3?d=identicon)[kobirbd93](/maintainers/kobirbd93)

---

Top Contributors

[![kobirbd93](https://avatars.githubusercontent.com/u/185674708?v=4)](https://github.com/kobirbd93 "kobirbd93 (7 commits)")

---

Tags

laravelpushnotificationgcmFCMandroidiosapn

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kobir-larapush-notification/health.svg)

```
[![Health](https://phpackages.com/badges/kobir-larapush-notification/health.svg)](https://phpackages.com/packages/kobir-larapush-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)
