Download the PHP package cofa/notification_via_firebase_and_database without Composer
On this page you can find all versions of the php package cofa/notification_via_firebase_and_database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cofa/notification_via_firebase_and_database
More information about cofa/notification_via_firebase_and_database
Files in cofa/notification_via_firebase_and_database
Package notification_via_firebase_and_database
Short Description This is a package for sending notificatinon via firebase and database with good code structure
License MIT
Informations about the package notification_via_firebase_and_database
Firebase & Database Notifications for Laravel
A Laravel package for sending push notifications via Firebase Cloud Messaging (FCM) and storing them in the database — using Laravel's native notification pipeline with a clean, channel-based architecture.
Features
- 🔥 Firebase Channel — Send push notifications via FCM using Laravel's standard
notify()pipeline - 💾 Database Channel — Store notifications using Laravel's built-in notification system
- 🏗️ Channel-Based Architecture — Fully integrated with
via(),toFirebase(), andtoDatabase() - 📱 Platform-Specific Configs — Android and iOS payload configuration support
- 🔑 Device Token Management — Built-in
user_device_tokenstable with active/inactive tracking - ✅ Fully Tested — Test suite using Orchestra Testbench and Mockery
- 🔍 Static Analysis — Psalm integration for type safety
Requirements
| Requirement | Version |
|---|---|
| PHP | ^8.2 |
| Laravel | ^10.0 \| ^11.0 \| ^12.0 |
| kreait/firebase-php | ^7.0 \| ^8.0 |
Installation
Install via Composer:
Register the Service Provider
Laravel 11+ — auto-discovered, no action needed.
Laravel 10 — add to config/app.php:
Configuration
1. Publish the Config File
This creates config/firebase-notification.php:
2. Add Your Firebase Credentials
- Go to Firebase Console → Project Settings → Service Accounts
- Click Generate new private key and download the JSON file
- Place it in your project (recommended:
storage/app/firebase/credentials.json) - Add the path to
.gitignore— never commit credentials to version control
3. Set Up the Database
This creates two tables:
notifications— Laravel's standard notifications tableuser_device_tokens— Stores FCM tokens per user and device
user_device_tokens Schema
| Column | Type | Description |
|---|---|---|
user_id |
foreignId | References users.id |
device_token |
string | Unique FCM device token |
device_type |
enum | android, ios, web |
device_name |
string (nullable) | Optional device label |
is_active |
boolean | Whether token is active |
last_used_at |
timestamp (nullable) | Last delivery timestamp |
Usage
1. Prepare Your User Model
Add the Notifiable trait and implement routeNotificationForFirebase:
2. Firebase + Database Notification (Combined)
Extend FirebaseNotification to send both push and database notifications at once:
Send it:
3. Firebase-Only Notification
4. Database-Only Notification
5. Reading Notifications
Advanced Usage
Platform-Specific Payload Configuration
Error Handling
Always wrap notifications in a try/catch for production use:
Common failure reasons:
- Missing credentials — credentials file path is wrong or file doesn't exist
- Invalid FCM token — token has expired or the app was uninstalled
- Network error — FCM service unreachable
Tip: When an FCM token returns a
NOT_REGISTEREDerror from Firebase, delete it fromuser_device_tokensto keep your token table clean.
Extending the Package
You can implement the Notification interface to create fully custom channels:
Architecture
Testing
Security
- ❌ Never commit your Firebase credentials JSON to version control
- ✅ Add the credentials path to
.gitignore - ✅ Use environment variables to define the credentials path
- ✅ Validate all user input before building notification payloads
- ✅ Regularly rotate Firebase service account keys
Contributing
Contributions, issues, and feature requests are welcome! Feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -m 'feat: add my feature') - Push to the branch (
git push origin feature/my-feature) - Open a Pull Request
Please make sure your PR includes tests and passes composer test and composer psalm.
Changelog
v2.0.0
- Refactored to use Laravel's native notification channel architecture
- Added
via(),toFirebase(),toDatabase()channel support - Improved service provider with auto-discovery for Laravel 11+
- Removed
tymon/jwt-authconflict - Added
tymon/jwt-authto dev dependencies to verify compatibility
v1.1.2
- Added conflict declaration with
tymon/jwt-auth
v1.1.1
- Added
setAndroidConfiguration()andsetIOSConfiguration()to payload
v1.1.0
- Improved payload contract structure
v1.0.x
- Initial releases
License
This package is open-source software licensed under the MIT license.
Credits
Author: Mahmoud Gamal Email: [email protected] GitHub: github.com/Cofa12
Support
For bugs, questions, or feature requests, please open an issue on GitHub.
All versions of notification_via_firebase_and_database with dependencies
kreait/firebase-php Version ^7.0|^8.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/config Version ^10.0|^11.0|^12.0|^13.0
illuminate/notifications Version ^10.0|^11.0|^12.0|^13.0