bilalmardini/firebase-notification
Composer 安装命令:
composer require bilalmardini/firebase-notification
包简介
Laravel Firebase Notification is a robust and user-friendly package designed to integrate Firebase Cloud Messaging (FCM) with Laravel applications. This package streamlines the process of sending notifications to users through Firebase, supporting various notification targeting options and customiza
关键字:
README 文档
README
Overview
Laravel Firebase Notification is a powerful package for integrating Firebase Cloud Messaging (FCM) into Laravel applications. It provides an intuitive interface for sending push notifications to users, targeting individuals, groups, or topics for broadcast notifications.
Features
- Push Notifications: Send notifications via Firebase Cloud Messaging (FCM).
- Topic-Based Notifications: Broadcast messages to subscribers.
- User-Specific Notifications: Send personalized messages.
- Custom Payloads: Include icons, titles, bodies, and additional data.
- Rich Media Support: Customizable message structure with deep linking.
- Secure Delivery: Authentication with Firebase using a service account key.
Requirements
- PHP: 7.4 or higher
- Laravel: 8.x or higher
- Firebase: A project with Cloud Messaging enabled
- Credentials: Firebase Service Account credentials
Installation
Install the package via Composer:
composer require bilalmardini/firebase-notification
If you are not using Laravel package auto-discovery, add the service provider in config/app.php:
'providers' => [ // Other Service Providers BilalMardini\FirebaseNotification\Providers\FirebaseNotificationServiceProvider::class, ],
Publish the configuration file to set up your Firebase credentials:
php artisan vendor:publish --provider="BilalMardini\FirebaseNotification\Providers\FirebaseNotificationServiceProvider"
Configuration
Set your Firebase credentials in the published configuration file (config/firebase.php):
return [ 'credentials_file_path' => base_path('firebase.json'), 'project_id' => 'your-firebase-project-id' ];
Usage
Sending a Notification
1. Topic-Based Notification (Global News Update)
Send a notification to all users subscribed to a specific topic:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use BilalMardini\FirebaseNotification\Facades\FirebaseNotification; class NewsNotificationController extends Controller { /** * Send a global news update to users subscribed to 'global-news'. * * @return \Illuminate\Http\JsonResponse */ public function sendGlobalNewsUpdate() { $result = FirebaseNotification::setTitle('Breaking News') ->setBody('A major event just happened. Click to read more.') ->setIcon('https://news-website.com/news-icon.png') ->setTopic('global-news') // Target 'global-news' topic ->setData(['news_id' => 5678, 'category' => 'breaking-news']) ->push(); return $result ? response()->json(['message' => 'News notification sent successfully.'], 200) : response()->json(['message' => 'Failed to send news notification.'], 500); } }
Key Points:
- Sends notifications to users subscribed to the
global-newstopic. - Includes custom data such as
news_idandcategory.
2. User-Specific Notification (Order Status)
Notify specific users about their order status:
<?php namespace App\Http\Controllers; use App\Models\User; use Illuminate\Http\Request; use BilalMardini\FirebaseNotification\Facades\FirebaseNotification; class PromotionNotificationController extends Controller { /** * Notify users about a new promotional offer. * * @return \Illuminate\Http\JsonResponse */ public function sendPromotionNotification() { $eligibleUsers = User::where('is_eligible_for_promo', true)->get(); $result = FirebaseNotification::setTitle('Exclusive Promotion Just for You!') ->setBody('Unlock your special offer now. Limited time only!') ->setIcon('https://yourstore.com/promo-icon.png') ->setUsers($eligibleUsers) // Target specific users ->setData(['promo_code' => 'PROMO2024', 'discount' => '20%']) ->push(); return $result ? response()->json(['message' => 'Promotion notification sent successfully.'], 200) : response()->json(['message' => 'Failed to send promotion notification.'], 500); } }
Key Points:
- Sends notifications to users eligible for a promotional offer (
is_eligible_for_promo). - Includes custom data like
promo_codeanddiscount.
Models
Notification Model
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Notification extends Model { use HasFactory; protected $fillable = [ 'title_en', 'title_ar', 'description_en', 'description_ar', 'is_general', ]; public function userNotifications() { return $this->hasMany(UserNotification::class); } }
UserNotification Model
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class UserNotification extends Model { use HasFactory; protected $fillable = [ 'notification_id', 'user_id', ]; public function notification() { return $this->belongsTo(Notification::class); } public function user() { return $this->belongsTo(User::class); } }
UserFcmToken Model
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class UserFcmToken extends Model { use HasFactory; protected $fillable = ['user_id', 'fcm_token']; public function user() { return $this->belongsTo(User::class); } }
Contact
If you have any questions or need further assistance, you can reach out through the following channels:
- GitHub Issues: Submit an issue for bug reports, feature requests, or general questions.
- Email: For direct inquiries, you can contact us at bilal.mardini1999@gmail.com.
We appreciate your interest in our project and your contributions. Thank you for being a part of the Laravel Firebase Notification community!
bilalmardini/firebase-notification 适用场景与选型建议
bilalmardini/firebase-notification 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 73 次下载、GitHub Stars 达 16, 最近一次更新时间为 2024 年 11 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notifications」 「laravel」 「push notifications」 「firebase」 「firebase php」 「Firebase Cloud Messaging」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bilalmardini/firebase-notification 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bilalmardini/firebase-notification 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bilalmardini/firebase-notification 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
Apple Push Notification & Feedback Provider
Laravel package to send push notifications to mobile devices (apns, gcm)
Captures outgoing SMS notifications
Send push notification to android|ios devices , support APNs, FCM
Alfabank REST API integration
统计信息
- 总下载量: 73
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-09