This package makes it easy to send notifications using Firebase Cloud Messaging (FCM) via new FCM HTTP v1 API with Laravel 5.3, 5.4, and 5.5.
Install this package with Composer:
composer require pixwell-dev/laravel-notification-channel-fcm
Register the ServiceProvider in your config/app.php (Skip this step if you are using Laravel 5.5):
NotificationChannels\Fcm\FcmServiceProvider::class,
You need to register for a server key from Firebase for your application. Start by creating a project here: https://console.firebase.google.com
Once you've registered and set up your project, add the firebase auth json file key to your configuration in config/broadcasting.php
'connections' => [
....
'fcm' => [
'json_file_path' => env('FIREBASE_CREDENTIALS'),
],
...
]
You can now send notifications via FCM by creating an FcmNotification
and an FcmMessages
:
class AccountActivated extends Notification
{
public function via($notifiable)
{
return [FcmChannel::class];
}
public function toFcm($notifiable)
{
// The FcmNotification holds the notification parameters
$fcmNotification = FcmNotification::create()
->withTitle('Your account has been activated')
->withBody('Thank you for activating your account.');
// The FcmMessage contains other options for the notification
return FcmMessage::create()
->setNotification($fcmNotification)
->setData([])
->setApns($apnsConfig)
->setAndroid($androidConfig)
->setWebpush($webpushConfig);
}
}
The Message
object always contains attributes (AndroidConfig
| ApnsConfig
| WebPushConfig
) for differ between different operating systems (Android, iOS, and Chrome). In this perspective, a Message
object is available for each
platform which extends the FcmMessage
object.
All the methods below are explained and defined in the Firebase Cloud Messaging documentation found here: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages This package wrap Firebase SDK for PHP package to laravel https://firebase-php.readthedocs.io/en/latest/cloud-messaging.html. You can use all available functions.
Please see CHANGELOG for more information what has changed recently.
$ composer test
If you discover any security related issues, please email balunjozef@gmail.com instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.