PHPackages                             aristosya/larafirebase - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. aristosya/larafirebase

ActiveLibrary[HTTP &amp; Networking](/categories/http)

aristosya/larafirebase
======================

Laravel Firebase Cloud Messaging.With SendAll() method

02.6k—0%PHP

Since Sep 12Pushed 1y agoCompare

[ Source](https://github.com/Aristosya/larafirebase-with-sendAll)[ Packagist](https://packagist.org/packages/aristosya/larafirebase)[ RSS](/packages/aristosya-larafirebase/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

### That's modified version of  . For personal use only. I don't claim any rights

[](#thats-modified-version-of-httpsgithubcomgg-innovativelarafirebase--for-personal-use-only-i-dont-claim-any-rights)

### Introduction

[](#introduction)

**Larafirebase** is a package thats offers you to send push notifications via Firebase in Laravel.

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.

For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.

### Installation

[](#installation)

Follow the steps below to install the package.

**Install via Composer**

```
composer require aristosya/larafirebase:dev-main

```

**Copy Configuration**

Run the following command to publish the `larafirebase.php` config file:

```
php artisan vendor:publish --provider="GGInnovative\Larafirebase\Providers\LarafirebaseServiceProvider"
```

**Configure larafirebase.php as needed**

Open the `larafirebase.php` configuration file, which you just published, and set the following values as needed:

- `project_id`: Replace with your actual Firebase project ID. (To get your project ID go to  -&gt; choose your project -&gt; Find "project settings (Inside Side-bar click on gear for now)" -&gt; In "General" tab copy your "Project ID"). BTW it must be a string.
- `firebase_credentials`: This refers to the JSON credentials file for your Firebase project. Make sure it points to the correct location in your project. This JSON file contains the authentication information for your Firebase project, allowing your Laravel application to interact with Firebase services. You can generate this JSON file in the Firebase Console. Once you have it, specify its path in this configuration. (To get your project JSON credentials FILE go to  -&gt; choose your project -&gt; Find "project settings (Inside Side-bar click on gear for now)" -&gt; In "Service accounts" tab choose Firebase Admin SDK -&gt; Generate new private key -&gt; download the file and then put it inside your app"). BTW for 'firebase\_credentials' =&gt; public\_path('firebase\_credentials.json') the file must be inside {project-folder}/public/, and the name of the file must be : "firebase\_credentials.json".

### Configure your front application for sendNotificationAll() method

[](#configure-your-front-application-for-sendnotificationall-method)

IF you will use send notifications to all user, you should initialize all the devise tokens to topic "all" inside your front application (NOT FOR LARAVEL). Example for Flutter:

```
import 'dart:convert';

import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get/get.dart';

import '../routes/app_routes.dart';

void onDidReceiveNotificationResponse(
    NotificationResponse notificationResponse) async {
  final payload =
      RemoteMessage.fromMap(jsonDecode(notificationResponse.payload ?? ""));
  if (notificationResponse.payload != null) {
    debugPrint('notification payload: $payload');
  }
  await Get.toNamed(Routes.testNotification, arguments: {"message": payload});
}

class FirebaseApi {
  final _firebaseMessaging = FirebaseMessaging.instance;

  final _androidChannel = const AndroidNotificationChannel(
      'high_importance_channel', 'High importance notifications',
      description: 'This channel is used for ipmortant notications',
      importance: Importance.defaultImportance);

  final _localNotifications = FlutterLocalNotificationsPlugin();

  Future initNotifications() async {
    await _firebaseMessaging.requestPermission();
    final fcmToken = await _firebaseMessaging.getToken();

// NEXT LINE MUST BE ADDED
    _firebaseMessaging.subscribeToTopic('all');
    debugPrint('FireBase Cloud Messaging Token == $fcmToken');
    initPushNotifications();
    initLocalNotifications();
  }

  // function to handle received message
  void handleMessage(RemoteMessage? message) async {
    if (message == null) {
      return;
    }
    await Get.toNamed(Routes.testNotification, arguments: {"message": message});
  }

  Future initLocalNotifications() async {
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
    const AndroidInitializationSettings initializationSettingsAndroid =
        AndroidInitializationSettings('@mipmap/ic_launcher');
    final InitializationSettings initializationSettings =
        InitializationSettings(
      android: initializationSettingsAndroid,
    );
    await _localNotifications.initialize(initializationSettings,
        onDidReceiveNotificationResponse: onDidReceiveNotificationResponse);
    final _platform = _localNotifications.resolvePlatformSpecificImplementation<
        AndroidFlutterLocalNotificationsPlugin>();
    await _platform?.createNotificationChannel(_androidChannel);
  }

  //function to init bg settings
  Future initPushNotifications() async {
    // handle when the app was terminated and it opeened now
    await FirebaseMessaging.instance
        .setForegroundNotificationPresentationOptions(
            alert: true, badge: true, sound: true);
    await FirebaseMessaging.instance.getInitialMessage().then(handleMessage);
    // attach an event listener
    FirebaseMessaging.onMessageOpenedApp.listen(handleMessage);
    FirebaseMessaging.onMessage.listen((message) {
      final notification = message.notification;
      if (notification == null) return;
      _localNotifications.show(
          notification.hashCode,
          notification.title,
          notification.body,
          NotificationDetails(
              android: AndroidNotificationDetails(
                  _androidChannel.id, _androidChannel.name,
                  channelDescription: _androidChannel.description,
                  icon: '@mipmap/ic_launcher')),
          payload: jsonEncode(message.toMap()));
    });
  }
}

```

If Im not mistaken for JAVA :

```
    FirebaseMessaging.getInstance().subscribeToTopic("TopicName");
```

### Configure your front application for sendNotificationUser()/sendNotificationUsers() method

[](#configure-your-front-application-for-sendnotificationusersendnotificationusers-method)

IF you will use send notifications to specific user/users by his/their id, you should initialize all the devise tokens to topic "user\_ID" inside your front application after login or registration, also delete deviceId from that topic after logout ! (NOT FOR LARAVEL).

Example for Flutter:

```
void login(){
    final _firebaseMessaging = FirebaseMessaging.instance;
    _firebaseMessaging.subscribeToTopic('user_$id');
}
void logout(){
    final _firebaseMessaging = FirebaseMessaging.instance;
    _firebaseMessaging.unsubscribeFromTopic('user_$id');
}

```

```
    login => FirebaseMessaging.getInstance().subscribeToTopic("user_" + id);
    logout=> FirebaseMessaging.getInstance().unsubscribeFromTopic("user_" + id);
```

### Usage

[](#usage)

Follow the steps below to find how to use the package.

Example usage in **Controller/Service** or any class:

```
use GGInnovative\Larafirebase\Facades\Larafirebase;

class MyController
{
public function sendNotification()
    {
        return Larafirebase::withTitle('Test Title')
            ->withBody('Test body')
            ->withImage('https://firebase.google.com/images/social.png')
            ->withAdditionalData([
                'name' => 'wrench',
                'mass' => '1.3kg',
                'count' => '3'
            ])
            ->withToken('TOKEN_HERE') // You can use also withTopic
            ->sendNotification();
    }

public function sendNotificationAll()
            {
                return Larafirebase::withTitle('Test Title')
                    ->withBody('Test body')
                    ->withImage('https://firebase.google.com/images/social.png')
                    ->withAdditionalData([
                        'name' => 'wrench',
                        'mass' => '1.3kg',
                        'count' => '3'
                    ])
                    ->sendNotificationAll();

        }

public function sendNotificationUser()
    {
        return Larafirebase::withTitle('Test Title')
            ->withBody('Test body')
            ->withImage('https://firebase.google.com/images/social.png')
            ->withAdditionalData([
                'name' => 'Some Name',
                'product_id' => '123',
                'user_id' => '3'
            ])
//            id of One user
            ->sendNotificationUser(1);
    }

public function sendNotificationUsers()
    {
        return Larafirebase::withTitle('Test Title')
            ->withBody('Test body')
            ->withImage('https://firebase.google.com/images/social.png')
            ->withAdditionalData([
                'name' => 'Some Name',
                'product_id' => '123',
                'user_id' => '3'
            ])
//            array of users ids
            ->sendNotificationUsers([0,2,1,4]);
    }
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 Bus Factor1

Top contributor holds 78.3% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/87494379?v=4)[Roman Alexandrovich](/maintainers/Aristosya)[@Aristosya](https://github.com/Aristosya)

---

Top Contributors

[![Aristosya](https://avatars.githubusercontent.com/u/87494379?v=4)](https://github.com/Aristosya "Aristosya (18 commits)")[![gentritabazi](https://avatars.githubusercontent.com/u/35135482?v=4)](https://github.com/gentritabazi "gentritabazi (5 commits)")

### Embed Badge

![Health badge](/badges/aristosya-larafirebase/health.svg)

```
[![Health](https://phpackages.com/badges/aristosya-larafirebase/health.svg)](https://phpackages.com/packages/aristosya-larafirebase)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)

PHPackages © 2026

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