Download the PHP package nylo/laravel-fcm-channel without Composer
On this page you can find all versions of the php package nylo/laravel-fcm-channel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nylo/laravel-fcm-channel
More information about nylo/laravel-fcm-channel
Files in nylo/laravel-fcm-channel
Package laravel-fcm-channel
Short Description Send Firebase Cloud Messenging (FCM) notifications from Laravel.
License MIT
Homepage https://github.com/nylo-core/laravel-fcm-channel
Informations about the package laravel-fcm-channel
Laravel FCM Channel
Manage FCM notifications with ease using Laravel FCM Channel.
Contents
- Installation
- Configuration
- Usage
- Changelog
- Security
- Contributing
- Credits
- License
This package has been built to make sending FCM messages easier.
There is also a Flutter package you can use to save time for mobile development.
Overview:
- Add multiple (FCM) devices to a model in Laravel
- API Routes for adding new devices to a model
- Send FCM notifications using the new "
fcm_channel
" in your Laravel Notification - Flutter mobile package to help speed up your development with notifications
Installation
First, install the package via composer:
The package will automatically register itself.
Configuration
Run the install
command.
This will add a (laravelfcm.php
) config file
ServiceProvider to your app.php: App\Providers\FcmAppServiceProvider::class
Then, ask if you want to run the migrations.
Here are the tables it will migrate:
- fcm_devices
Add your Google Service Account to config/firebase_service_account_json
.
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.
Then, paste the JSON into the firebase_service_account_json
file like in the above example.
Note: It's best to keep the key values in a
.env
file. Don't commit the JSON file to your repository.
You can configure this package in config/laravelfcm.php
.
Configuring your Model
Add the HasFcmDevices
trait to your User Model.
This package uses laravel/sanctum
as the default middleware for your model.
However, if you want authenticate using a different middleware, you can update the middleware
key in your config/laravelfcm.php file.
API Endpoints
This package adds API endpoints to your router to allow your application to store devices.
Postman collection example
Store a device
The default endpoint: /api/fcm/device
Method: PUT
Authorization: "Bearer {{Sanctum Token}}"
Add this header key: X-DMeta
Value:
Payload body:
This will add a new FCM device for a User.
If you provide a fcm_token
in the payload then the user will be able to receive push notifications.
Usage
Sending Notifications
To send a notification using the FCMChannel, first create a Notification in your Laravel project.
After creating your notification, add a fcm_channel
to the array below.
Then, add the following snippet to your notification class.
Send a Notification
This will send a notification to the user's devices.
Control if an FCM notification should be sent
In some scenarios, you may only want to notify a user based on a condition.
In your User
model class, add the following snippet.
By default, the
canSendNotification
method will returntrue
.
Notification Object
Here are the attributes you can assign to a FcmMessage
.
Relationships
When your model is using the HasFcmDevices
trait you can call the following methods.
Flutter Plugin
Need to send notifications to a Flutter application?
Check out the official repository for that project here.
Changelog
Please see CHANGELOG for recent changes.
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for details.
Credits
- Anthony Gordon
- All Contributors
License
The MIT License (MIT). Please view our License File for more information.
All versions of laravel-fcm-channel with dependencies
illuminate/support Version ~5.8.0|6.x|7.x|8.x|9.x|10.x|11.x
kreait/firebase-php Version ^7.12