liliom / laravel-firebase
Laravel FCM (Firebase Cloud Messaging) Notification Channel
Installs: 26 019
Dependents: 0
Suggesters: 0
Security: 0
Stars: 24
Watchers: 2
Forks: 12
Open Issues: 1
pkg:composer/liliom/laravel-firebase
Requires
- php: >=5.5.9
- guzzlehttp/guzzle: ~6.0
- illuminate/support: 5.*
This package is auto-updated.
Last update: 2025-10-26 14:24:39 UTC
README
This package makes it easy to send notifications using Firebase Cloud Messaging (FCM) with Laravel Notification Channel.
Installation
This package can be installed through Composer.
composer require liliom/laravel-firebase
If you don't use Laravel 5.5+ you have to add the service provider manually
// config/app.php 'providers' => [ ... Liliom\Firebase\FirebaseServiceProvider::class, ... ];
Now add you Firebase API Key in config/services.php.
return [ .... 'firebase' => [ 'key' => '' ], .... ];
Usage
Les's create a notification using artisan commend:
php artisan make:notification FirebaseNotification
Now you can use firebase channel in your vie() mothod.
public function via($notifiable) { return ['firebase']; }
Add a pubilc method toFirebase($notifiable) to your notification class, and return an instance of FirebaseMessage:
public function toFirebase($notifiable) { return (new \Liliom\Firebase\FirebaseMessage) ->notification([ 'title' => 'Notification title', 'body' => 'Notification body', 'sound' => '', // Optional 'icon' => '', // Optional 'click_action' => '' // Optional ]) ->setData([ 'param' => 'zxy' // Optional ]) ->setPriority('high'); // Default is 'normal' }
Available methods:
setData: To Setdata.setPriority: To Setpriority.setTimeToLive: To Settime_to_live.setCollapseKey: To Setcollapse_key.setNotification: To Setnotification.setCondition: To Setcondition.setContentAvailable: To Setcontent_available.setMutableContent: To Setmutable_content.setPackageName: To Setrestricted_package_name.
When sending to specific device(s), make sure your notifiable entity has routeNotificationForFirebase method defined:
Note: You can send to many devices by return an array of tokens.
/** * Route notifications for Firebase channel. * * @return string|array */ public function routeNotificationForFirebase() { return $this->device_tokens; }
License
The MIT License (MIT). Please see License File for more information.