| Package Data | |
|---|---|
| Maintainer Username: | mkwsra |
| Maintainer Contact: | hussam3bd@liliom.co (Hussam Abd) |
| Package Create Date: | 2017-08-12 |
| Package Last Update: | 2019-09-19 |
| Home Page: | |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-28 03:06:14 |
| Package Statistics | |
|---|---|
| Total Downloads: | 26,018 |
| Monthly Downloads: | 42 |
| Daily Downloads: | 16 |
| Total Stars: | 24 |
| Total Watchers: | 2 |
| Total Forks: | 12 |
| Total Open Issues: | 1 |
This package makes it easy to send notifications using Firebase Cloud Messaging (FCM) with Laravel Notification Channel.
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' => ''
],
....
];
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'
}
setData: To Set data.setPriority: To Set priority.setTimeToLive: To Set time_to_live.setCollapseKey: To Set collapse_key.setNotification: To Set notification.setCondition: To Set condition.setContentAvailable: To Set content_available.setMutableContent: To Set mutable_content.setPackageName: To Set restricted_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;
}
The MIT License (MIT). Please see License File for more information.