wetillix/push-notification
is a simple and efficient PHP package for sending notifications via Firebase Cloud Messaging (FCM).
Install the package via Composer:
composer require wetillix/push-notification
After installation, prepare your firebase_credentials.json
file containing your FCM credentials. Store this file securely in your project.
Import and initialize the service in your project, providing the path to the FCM credentials file in the constructor:
use Wetillix\PushNotification\PushNotification;
$pushNotification = new PushNotification('/path/to/firebase_credentials.json');
Use the sendPushNotificationToDevice
method to send a notification to a user:
$response = $pushNotification->sendPushNotificationToDevice(
token: 'device_token',
data: [
'title' => 'value1',
'description' => 'value2'
]
);
Use the sendPushNotificationToTopic
method to send a notification to all users subscribed to a topic:
$response = $pushNotification->sendPushNotificationToTopic(
topic: 'topic_name',
data: [
'title' => 'value1',
'description' => 'value2'
]
);
Contributions are welcome! Follow these steps:
- Fork the project.
- Create a new branch:
git checkout -b my-branch
. - Make your changes.
- Submit a Pull Request.
This project is licensed under the MIT license.