|
1 | | -# laravel_notify_fcm |
| 1 | +# Laravel Notify Fcm |
2 | 2 |
|
3 | | -A new Flutter package. |
| 3 | +<p align="center"> |
| 4 | + <a href="https://github.com/nylo-core/laravel-notify-fcm/releases/latest"><img src="https://img.shields.io/github/v/release/nylo-core/laravel-notify-fcm?style=plastic" alt="Latest Release Version"></a> |
| 5 | + <a href="https://github.com/nylo-core/laravel-notify-fcm/releases/latest"><img src="https://img.shields.io/github/license/nylo-core/laravel-notify-fcm?style=plastic" alt="Latest Stable Version"></a> |
| 6 | + <a href="https://github.com/nylo-core/laravel-notify-fcm"><img alt="GitHub stars" src="https://img.shields.io/github/stars/nylo-core/laravel-notify-fcm?style=plastic"></a> |
| 7 | +</p> |
4 | 8 |
|
5 | | -## Getting Started |
| 9 | +Laravel Notify Fcm if package for sending notifications to your Flutter app using Laravel FCM. |
6 | 10 |
|
7 | | -This project is a starting point for a Dart |
8 | | -[package](https://flutter.dev/developing-packages/), |
9 | | -a library module containing code that can be shared easily across |
10 | | -multiple Flutter or Dart projects. |
| 11 | +## Getting started |
11 | 12 |
|
12 | | -For help getting started with Flutter, view our |
13 | | -[online documentation](https://flutter.dev/docs), which offers tutorials, |
14 | | -samples, guidance on mobile development, and a full API reference. |
| 13 | +### Installation |
| 14 | + |
| 15 | +Add the following to your `pubspec.yaml` file: |
| 16 | + |
| 17 | +``` yaml |
| 18 | +dependencies: |
| 19 | + laravel_notify_fcm: ^0.0.1 |
| 20 | +``` |
| 21 | +
|
| 22 | +or with Dart: |
| 23 | +
|
| 24 | +``` bash |
| 25 | +dart pub add laravel_notify_fcm |
| 26 | +``` |
| 27 | + |
| 28 | +### Requirements |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +First, install the package via composer: |
| 33 | + |
| 34 | +``` bash |
| 35 | +composer require nylo-core/laravel-fcm-channel |
| 36 | +``` |
| 37 | + |
| 38 | +The package will automatically register itself. |
| 39 | + |
| 40 | +## Configuration |
| 41 | + |
| 42 | +Run the `install` command. |
| 43 | + |
| 44 | +```bash |
| 45 | +php artisan laravelfcm:install |
| 46 | +``` |
| 47 | +This will add a (`laravelfcm.php`) config file |
| 48 | + |
| 49 | +ServiceProvider to your app.php: `App\Providers\FcmAppServiceProvider::class` |
| 50 | + |
| 51 | +Then, ask if you want to run the migrations. |
| 52 | + |
| 53 | +Here's the tables it will migrate: |
| 54 | +* fcm_devices |
| 55 | + |
| 56 | +Add your Google Service Account to `firebase_service_account_json`. |
| 57 | + |
| 58 | +```php |
| 59 | +<?php |
| 60 | + |
| 61 | +return '{ |
| 62 | + "type": "service_account", |
| 63 | + "project_id": "123456789-me908", |
| 64 | + "private_key_id": "123456789", |
| 65 | + "private_key": "-----BEGIN PRIVATE KEY-----\123456789\n-----END PRIVATE KEY-----\n", |
| 66 | + "client_email": "firebase-adminsdk-9p9z7@123456789-me908.iam.gserviceaccount.com", |
| 67 | + "client_id": "123456789", |
| 68 | + "auth_uri": "https://accounts.google.com/o/oauth2/auth", |
| 69 | + "token_uri": "https://oauth2.googleapis.com/token", |
| 70 | + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", |
| 71 | + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-9p9z7%123456789-me908.iam.gserviceaccount.com", |
| 72 | + "universe_domain": "googleapis.com" |
| 73 | + }'; |
| 74 | +``` |
| 75 | + |
| 76 | +You can download your Google Service Account in your Firebase Project Settings > Service Accounts > Manage service account permissions > "Actions (three dots) - Manage keys" > Add Key > Create New Key. |
| 77 | + |
| 78 | +Then, paste the JSON into the `firebase_service_account_json` file like in the above example. |
| 79 | +> **Note:** It's best to keep the key values in a `.env` file. Don't commit the JSON file to your repository. |
| 80 | +
|
| 81 | +You can fully configure this package in the `config/laravelfcm.php` file (this file should be added after you run `php artisan laravelfcm:install`). |
| 82 | + |
| 83 | +### Usage |
| 84 | + |
| 85 | +``` dart |
| 86 | +import 'package:laravel_notify_fcm/laravel_notify_fcm.dart'; |
| 87 | +
|
| 88 | +``` |
| 89 | + |
| 90 | +### Adding a device to the database |
| 91 | + |
| 92 | +First, call `init` to initialize the package. |
| 93 | + |
| 94 | +Parameters: |
| 95 | +- `url` - The URL to your Laravel app where the package will send the device token. |
| 96 | +- `firebaseMessaging` - The FirebaseMessaging instance. |
| 97 | +- `debugMode` - Whether to enable debug mode. Default is `false`. |
| 98 | + |
| 99 | +```dart |
| 100 | +FirebaseMessaging firebaseMessaging = FirebaseMessaging(); |
| 101 | +
|
| 102 | +await LaravelNotifyFcm.instance.init( |
| 103 | + url: 'https://example.com/api/fcm/devices', |
| 104 | + firebaseMessaging: firebaseMessaging, |
| 105 | +); |
| 106 | +``` |
| 107 | + |
| 108 | +Then, call `storeFcmDevice` to add the device to the database. |
| 109 | + |
| 110 | +``` dart |
| 111 | +
|
| 112 | +await LaravelNotifyFcm.instance.storeFcmDevice( |
| 113 | + sanctumToken: 'from your laravel user', |
| 114 | +); |
| 115 | +``` |
| 116 | + |
| 117 | +This method will request permission to send notifications to the device. If the user accepts, the device will be added to the database. |
| 118 | + |
| 119 | +Try the [example](/example) app to see how it works. |
| 120 | + |
| 121 | +## Changelog |
| 122 | +Please see [CHANGELOG](https://github.com/nylo-core/laravel-notify-fcm/blob/master/CHANGELOG.md) for more information what has changed recently. |
| 123 | + |
| 124 | +## Social |
| 125 | +* [Twitter](https://twitter.com/nylo_dev) |
| 126 | + |
| 127 | +## Licence |
| 128 | + |
| 129 | +The MIT License (MIT). Please view the [License](https://github.com/nylo-core/laravel-notify-fcm/blob/main/LICENSE) File for more information. |
0 commit comments