Laravel FCM Notifications Package

This package simplifies sending Firebase Cloud Messaging (FCM) push notifications within Laravel applications. Leveraging Google's Firebase API, it streamlines the process of delivering targeted messages to your users, enhancing engagement and providing a robust communication channel.

logo

Requirements

key

Laravel

Requires Laravel 8, 9, or 10 for compatibility and access to necessary features. Ensure your Laravel installation meets this version requirement for seamless integration.

key

PHP Version

PHP 8.0 or higher is necessary for optimal performance and support of the package's functionalities. Check your PHP version and update if needed.

key

Google API Client

The Google API Client is automatically installed via Composer, simplifying the setup process. This handles the communication with the Firebase API.

key

Firebase Setup

A Firebase account with the Cloud Messaging API enabled is crucial. This provides the necessary authentication and infrastructure for sending notifications.

requirements
installation

Installation

key

Composer Installation

Use Composer to install the package: `composer require digimantra/digi-notification`This command fetches and installs the necessary files and dependencies.

key

Publish Configuration

Publish the configuration file using the Artisan command: `php artisan vendor:publish --tag=config --provider="DigiNotificationFcmHelperFcmServiceProvider"`This creates the config file.

key

Environmental Variables

Set up environment variables in your `.env` file: `FIREBASE_PROJECT_ID=your-firebase-project-id FIREBASE_CREDENTIALS=path/to/your/credentials.json`. Obtain credentials FIREBASE_CREDENTIALS=path/to/your/credentials.json`. Obtain credentials from the Firebase Console.

Usage: Sending Notifications

Namespaces

Use the necessary namespace: `use DigiNotificationFcmHelper;`This ensures proper access to the the package's functionalities.

Variable Assignment

Assign variables for tokens, title, body, and optional data. Ensure the tokens array contains valid device tokens.

Dispatching Notifications

Use `FcmHelper::sendFcmNotification($tokens, $title, $body, $data);` to send the notification. This function handles the API interaction.

sending-notifications
development-and-testing

Configuration: Queueing

key

Queue Setup

Configure your queue system in your `.env` file: `QUEUE_CONNECTION=database`. Choose a suitable queue driver based on your application's needs.

key

Database Migration

Create the jobs table and run migrations: `php artisan queue:table php queue:table php artisan migrate`. This sets up the necessary database tables for queue processing.

key

Queue Worker

Run a queue worker to process background jobs. This ensures efficient handling of notification sending, improving and reliability.

Logging

Enable Logging

Set `FCM_LOGGING=true` in your `.env` file. This enables detailed logging of notification sending attempts, successes, and failures. Useful for debugging.

Disable Logging

Set `FCM_LOGGING=false` to disable logging. This reduces overhead, especially in production environments where detailed logs might not be necessary.

Log File Location

Check your Laravel log file for detailed information. The location of of this file depends on your Laravel configuration. This allows for for detailed post-mortem analysis.

Troubleshooting

Issue

Delivery Failures

Solution

Verify FCM tokens are valid and and up-to-date. Invalid tokens will result in failed deliveries.

Issue

Authentication Errors

Solution

Ensure your Firebase service account credentials are correct and have the necessary permissions. Double--check the `credentials.json`file path.

License and Support

support

MIT License

This package is open-source under the MIT license. Feel free to use, modify, and distribute it according to the license terms.

support

Support

For support or additional information, contact
it@digimantra.com