An open API service indexing awesome lists of open source software.

https://github.com/avto-dev/firebase-notifications-laravel

Notifications channel for Firebase service
https://github.com/avto-dev/firebase-notifications-laravel

firebase laravel notifications

Last synced: about 1 year ago
JSON representation

Notifications channel for Firebase service

Awesome Lists containing this project

README

          


Laravel

> Here's the latest documentation on Laravel Notifications System:

# Firebase notifications channel for Laravel applications

[![Version][badge_packagist_version]][link_packagist]
[![PHP Version][badge_php_version]][link_packagist]
[![Build Status][badge_build_status]][link_build_status]
[![Coverage][badge_coverage]][link_coverage]
[![Downloads count][badge_downloads_count]][link_packagist]
[![License][badge_license]][link_license]

This package makes it easy to send notifications using [Firebase][firebase_home] with Laravel 5.

## Contents

- [Installation](#installation)
- [Setting up the Firebase service](#setting-up-the-Firebase-service)
- [Usage](#usage)
- [Available Message methods](#available-message-methods)
- [Changelog](#changelog)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

## Installation

```bash
$ composer require avto-dev/firebase-notifications-laravel "^2.0"
```

> Installed `composer` is required ([how to install composer][getcomposer]).

> You need to fix the major version of package.

Laravel 5.5 and above uses Package Auto-Discovery, so doesn't require you to manually register the service-provider. Otherwise you must add the service provider to the `providers` array in `./config/app.php`:

```php
[
// ...
AvtoDev\FirebaseNotificationsChannel\ServiceProvider::class,
],

];
```

### Setting up the Firebase service

You need to set up firebase channel in config file `./config/services.php`.

**To generate a private key file for your service account:**

1. In the Firebase console, open **Settings > [Service Accounts][firebase_service_account]**.
1. Click **Generate New Private Key**, then confirm by clicking **Generate Key**.
1. Securely store the JSON file containing the key. You'll need this JSON file to complete the next step.

Next select the "driver" `file` or `config` contains credintails for [Firebase service account][firebase_service_account] in `./config/services.php`:

```php
[

/*
|----------------------------------------------------------------------
| Firebase service driver
|----------------------------------------------------------------------
|
| Value `file` or `config`:
| - Select `file` option to make service read json file
| - Select `config` option to set up all section in config file
|
*/

'driver' => env('FCM_DRIVER', 'config'),

/*
|---------------------------------------------------------------------
| FCM Drivers
|---------------------------------------------------------------------
|
| Here are each of the firebase.
|
*/

'drivers' => [

'file' => [
'path' => env('FCM_FILE_PATH', base_path('storage/fcm.json')),
],

'config' => [

/*
|------------------------------------------------------------
| Credentials
|------------------------------------------------------------
|
| Content of `firebase.json` file in config. Using if
| `fcm.driver` is `config`. All fields required!
|
*/

'credentials'=>[
'private_key_id' => env('FCM_CREDENTIALS_PRIVATE_KEY_ID', 'da80b3bbceaa554442ad67e6be361a66'),
'private_key' => env('FCM_CREDENTIALS_PRIVATE_KEY', '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n'),
'client_email' => env('FCM_CREDENTIALS_CLIENT_EMAIL', 'firebase-adminsdk-mwax6@test.iam.gserviceaccount.com'),
'client_id' => env('FCM_CREDENTIALS_CLIENT_ID', '22021520333507180281'),
'auth_uri' => env('FCM_CREDENTIALS_AUTH_URI', 'https://accounts.google.com/o/oauth2/auth'),
'token_uri' => env('FCM_CREDENTIALS_TOKEN_URI', 'https://oauth2.googleapis.com/token'),
'auth_provider_x509_cert_url' => env('FCM_CREDENTIALS_AUTH_PROVIDER_CERT', 'https://www.googleapis.com/oauth2/v1/certs'),
'client_x509_cert_url' => env('FCM_CREDENTIALS_CLIENT_CERT', 'https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-mwax6%40test.iam.gserviceaccount.com'),
],
],
],
],

];
```

## Usage

Now you can use the channel in your `via()` method inside the notification as well as send a push notification:

```php
setTitle('Approved!')
->setBody('Your account was approved!');
}
}
```

```php