Cloud Message is a Laravel package that provides a simple and unified way to send push notifications using Firebase Cloud Messaging (FCM) and Huawei Push Kit.
- Send push notifications via Firebase Cloud Messaging (FCM)
- Send push notifications via Huawei Push Kit
- Unified API for both FCM and Huawei
- Easy to use Facade
- Customizable configuration
- Robust error handling
- PHP 7.3+
- Laravel 7.0+
You can install the package via composer:
composer require medianet-dev/cloud-message
After installation, publish the config file:
php artisan vendor:publish --provider="MedianetDev\CloudMessage\CloudMessageServiceProvider" --tag="config"
This will create a config/cloud_message.php
file in your app's configuration directory. Here you can set your Firebase and Huawei credentials.
You can use the CloudMessage
facade to send notifications:
use MedianetDev\CloudMessage\Facade\CloudMessage;
$message = [
'title' => "Your notification title",
'body' => "Your notification body",
];
$registrationTokens = [
'token1',
'token2'
];
// Send via Firebase (default)
$results = CloudMessage::sendToTokens($message, $registrationTokens);
// Send via Huawei
$results = CloudMessage::sendToTokens($message, $registrationTokens, 'huawei');
You can also use the FirebaseNotification
class directly:
use MedianetDev\CloudMessage\Drivers\FirebaseNotification;
$message = [
'title' => "Your notification title",
'body' => "Your notification body",
];
$registrationTokens = [
'token1',
'token2'
];
$results = FirebaseNotification::sendToTokens($message, $registrationTokens);
$topic = 'guests'
$registrationTokens = [
'token1',
'token2'
];
$results = FirebaseNotification::subscribeToTopic($topic, $registrationTokens);
This will subscribe the provided tokens to receive notifications for the given topic.
$topic = 'guests'
$registrationTokens = [
'token1',
'token2'
];
$results = FirebaseNotification::unsubscribeToTopic($topic, $registrationTokens);
Removes the subscription of the tokens from the given topic.
For performance optimizations when sending notifications to large numbers of tokens, the package supports asynchronous multi-token requests.
To enable this feature, configure the async_requests
option in the config file:
return [
// Other configurations...
'async_requests' => env('CLOUD_MESSAGE_ASYNC_REQUESTS', false),
];
You will need to ensure your queue worker is running to process these asynchronous jobs. From the command line, run: php artisan queue:work
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.