Simple Laravel FCM
Simple package for using FCM as Push Notification. With multiple token or device ID and send with topics., (*1)
Installation
You can pull the package via composer :, (*2)
``` bash
$ composer require idstack/laravel-fcm, (*3)
Register the service provider :
``` php
'Providers' => [
...
Idstack\Fcm\FcmServiceProvider::class,
]
```
Optional using facade:
```php
'aliases' => [
...
'Fcm' => Idstack\Fcm\Facades\Fcm::class,
];
Publish the config file to define your server key :, (*4)
php artisan vendor:publish --provider="Idstack\Fcm\FcmServiceProvider"
This is the contents of the published file:, (*5)
return [
/**
* Insert your FCM Server Key Here
* Or you can add in env file with FCM_SERVER_KEY variable
*/
'fcm_server_key' => env('FCM_SERVER_KEY','')
];
Usage
This sample usage for sending notification to any devices with several information like title and body notification :, (*6)
fcm()
->data([
'title' => 'Test FCM',
'body' => 'This is a test of FCM',
])
->to($recipients); // $recipients must an array
This sample usage for sending notification using topics with several information like title and body notification :, (*7)
fcm()
->data([
'title' => 'Test FCM',
'body' => 'This is a test of FCM',
])
->toTopics($recipients); // $recipients must an array