PHPackages                             kz370/laravel-firebase-notifications - 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. kz370/laravel-firebase-notifications

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

kz370/laravel-firebase-notifications
====================================

A Laravel package for sending Firebase Cloud Messaging (FCM) notifications using service accounts.

1.0.0(7mo ago)00MITPHPPHP ^8.0

Since Oct 10Pushed 7mo agoCompare

[ Source](https://github.com/kz370/kz370-laravel-firebase-notifications)[ Packagist](https://packagist.org/packages/kz370/laravel-firebase-notifications)[ RSS](/packages/kz370-laravel-firebase-notifications/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

🚀 kz370/laravel-firebase-notifications
======================================

[](#-kz370laravel-firebase-notifications)

A simple and flexible **Laravel package** for sending **Firebase Cloud Messaging (FCM)** notifications using a Firebase **Service Account**. Supports both **direct (instant)** and **queued (asynchronous)** notifications — including **topic-based broadcasts**.

---

🧩 Features
----------

[](#-features)

- ✅ Send notifications to **individual devices** or **specific topics**
- ✅ Supports **queued notifications** for scalable delivery
- ✅ Uses **Firebase Admin REST API v1** (no legacy FCM keys)
- ✅ Fully configurable via `.env`
- ✅ Compatible with **Laravel 9, 10, and 11**

---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require kz370/laravel-firebase-notifications
```

---

⚙️ Configuration
----------------

[](#️-configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="Kz370\FirebaseNotifications\FirebaseNotificationServiceProvider" --tag=config
```

This creates `config/firebase-notifications.php`.

### .env Setup

[](#env-setup)

Add your Firebase credentials and project ID:

```
FIREBASE_SERVICE_ACCOUNT=storage/app/firebase-service-account.json
FIREBASE_PROJECT_ID=your-firebase-project-id
```

> 💡 **Tip:** Download your Firebase service account key from **Project Settings → Service Accounts → Generate New Private Key**

---

🚀 Usage Examples
----------------

[](#-usage-examples)

### Send Notification to a Specific Device

[](#send-notification-to-a-specific-device)

```
use FirebaseNotification;

$deviceToken = 'your-device-token-here';

FirebaseNotification::sendNotification(
    $deviceToken,
    'Hello there!',
    'Welcome to our platform 🎉',
    'https://example.com/welcome-banner.png',
    ['type' => 'welcome', 'user_id' => 123]
);
```

### Method: sendNotification()

[](#method-sendnotification)

This method sends a push notification directly to a specific device using its FCM device token.

```
sendNotification(
    string $deviceToken,
    string $title,
    string $body,
    ?string $imageUrl = null,
    array $data = []
): array
```

**Parameters:**

ParameterTypeRequiredDescription`$deviceToken``string`✅The Firebase device token that identifies a specific user's device. You typically get this from your mobile app's Firebase SDK.`$title``string`✅The title text of the notification, usually displayed in bold (e.g., "New Message").`$body``string`✅The main message content or body text of the notification.`$imageUrl``string|null`❌(Optional) URL of an image to display in the notification if supported by the client app.`$data``array`❌(Optional) A custom key-value data payload sent alongside the notification. Useful for deep links or background processing.---

### Send Notification to a Topic

[](#send-notification-to-a-topic)

You can send notifications to any topic your users have subscribed to. By default, the topic is `"all"` — but you can specify your own.

```
FirebaseNotification::sendNotificationToTopic(
    'System Update',
    'We're upgrading our system tonight.',
    'https://example.com/update-banner.png',
    ['maintenance_mode' => true],
    'news'
);
```

This will send the notification to all users subscribed to the topic **`news`**.

### Method: sendNotificationToTopic()

[](#method-sendnotificationtotopic)

```
sendNotificationToTopic(
    string $title,
    string $body,
    ?string $imageUrl = null,
    array $data = [],
    string $topic = 'all'
): array
```

**Parameters:**

ParameterTypeRequiredDescription`$title``string`✅The notification title shown in the header (e.g., `"System Update"`)`$body``string`✅The main notification body text (e.g., `"We're upgrading our system tonight."`)`$imageUrl``string|null`❌Optional image URL to display in the notification (if supported)`$data``array`❌Custom key-value payload for background handling or deep linking`$topic``string`❌Target topic (default: `"all"`)---

⏳ Using Queues
--------------

[](#-using-queues)

You can queue notifications for background processing using Laravel's queue system.

### Queue Single Device Notification

[](#queue-single-device-notification)

```
use Kz370\FirebaseNotifications\Jobs\FirebaseNotificationJob;

FirebaseNotificationJob::dispatch(
    $deviceToken,
    'Queued Message',
    'This notification is sent via the queue!'
);
```

### Queue Topic Notification

[](#queue-topic-notification)

```
FirebaseNotificationJob::dispatch(
    null,
    'Breaking News',
    'Something big just happened!',
    null,
    ['category' => 'news'],
    true // Indicates it's for a topic
);
```

### Delay Notification

[](#delay-notification)

```
FirebaseNotificationJob::dispatch(
    $deviceToken,
    'Reminder',
    'Your session starts soon.'
)->delay(now()->addMinutes(10));
```

Make sure your queue worker is running:

```
php artisan queue:work
```

---

⚡ Configuration Overview
------------------------

[](#-configuration-overview)

`config/firebase-notifications.php`

```
return [
    'service_account_path' => env('FIREBASE_SERVICE_ACCOUNT', storage_path('app/firebase-service-account.json')),
    'project_id' => env('FIREBASE_PROJECT_ID', 'your-project-id'),
];
```

---

🧰 Troubleshooting
-----------------

[](#-troubleshooting)

### invalid\_grant or unauthorized\_client

[](#invalid_grant-or-unauthorized_client)

Check that your Firebase service account JSON file is valid and the `.env` path is correct.

### Notification not delivered

[](#notification-not-delivered)

- The device token must be valid and active
- Ensure the app is subscribed to the topic you're sending to
- The Firebase Cloud Messaging API must be enabled in Google Cloud Console

### Queues not processing

[](#queues-not-processing)

Run your queue worker:

```
php artisan queue:work
```

---

🪪 License
---------

[](#-license)

This package is open-source software licensed under the [MIT License](LICENSE).

---

✨ Author
--------

[](#-author)

**KZ370**
💻 Laravel Developer

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

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

Unknown

Total

1

Last Release

215d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a83ad798b7fe8683b4388105008c4cf18937268bf490bc8379528d362cfc5117?d=identicon)[khaledz370](/maintainers/khaledz370)

---

Top Contributors

[![kz370](https://avatars.githubusercontent.com/u/94254886?v=4)](https://github.com/kz370 "kz370 (1 commits)")

### Embed Badge

![Health badge](/badges/kz370-laravel-firebase-notifications/health.svg)

```
[![Health](https://phpackages.com/badges/kz370-laravel-firebase-notifications/health.svg)](https://phpackages.com/packages/kz370-laravel-firebase-notifications)
```

###  Alternatives

[mckenziearts/laravel-notify

Flexible flash notifications for Laravel

1.7k1.1M5](/packages/mckenziearts-laravel-notify)[s-ichikawa/laravel-sendgrid-driver

This library adds a 'sendgrid' mail driver to Laravel.

4139.3M1](/packages/s-ichikawa-laravel-sendgrid-driver)[laravel-notification-channels/apn

Apple APN Push Notification Channel

2021.9M4](/packages/laravel-notification-channels-apn)[laravel-notification-channels/microsoft-teams

A Laravel Notification Channel for Microsoft Teams

1603.0M7](/packages/laravel-notification-channels-microsoft-teams)[laravel-notification-channels/discord

Laravel notification driver for Discord.

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

The Illuminate Mail package.

5910.1M391](/packages/illuminate-mail)

PHPackages © 2026

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