nht/notification
Composer 安装命令:
composer require nht/notification
包简介
This Laravel package provides a simple, unified way to send notifications across multiple channels— Email, SMS, and Push Notifications—with minimal setup. Designed for developers who value efficiency and flexibility, it streamlines the process of reaching users wherever they are.
README 文档
README
Version: 2.2.0
Author: Nazmul Hasan
License: MIT
Framework: Laravel 10 / 11
PHP: >= 8.1
🧩 Overview
A modern Laravel package for sending SMS, Email, and Push notifications seamlessly across your application.
Easily queue and localize notifications with one unified interface.
⚙️ Installation
🪄 Step 1: Install Package
composer require nht/notification
⚙️ Step 2: Enable Queues
Edit your .env file:
QUEUE_CONNECTION=database
Then create queue tables:
php artisan queue:table php artisan queue:failed-table php artisan migrate
⚡ Step 3: Publish Configurations
php artisan nht-notification:published
🧠 Import Class
use NH\Notification\Notifications\Notification;
You can now send SMS, Email, or Push notifications — separately or together.
📱 SMS Notifications
✉️ Option 1 — Using Notification::send()
Notification::send([ 'sms' => [ 'phone' => '+60135871622', // 'sms_to_users' => $users, // Optional: send to a specific user 'message' => 'Write message here...', ], ]);
💬 Option 2 — Using Notification::sendSms()
Notification::sendSms([ 'phone' => '+18777804236', 'message' => 'Write message here...', ]);
📧 Email Notifications
$users = \App\Models\User::all();
🧰 Option 1 — Template Email
To define the base view path, add to your .env file:
MAIL_TEMPLATE_PATH=emails
Notification::sendMailWithTemplate([ 'template' => ['withdrawal notification', 'Subject'], // ['view', 'subject key'] 'subject' => 'Withdrawal Request', 'mail_to_users' => $users, 'data' => [ 'user_name' => 'Anik Da', 'amount' => 1000, 'submitted_by' => 'Lukmanul Hakim Hasibuan', 'status' => 'Pending', 'transaction_view_on' => route('customer.product'), ], ]);
📩 Option 2 — Registration Notification
Notification::send([ 'mail-template' => [ 'template' => ['registration', 'Subject'], 'subject' => 'Welcome to ALJ Harmony', 'mail_to' => 'email@email.com', // or ['email1', 'email2'] 'mail_to_users' => $users, 'data' => (object)[ 'user_name' => 'Anik Da', 'role' => 'Agency Admin', 'agency_name' => 'ALJ Harmony', 'email' => 'example@email.com', 'login_on' => route('customer.product'), ], ] ]);
🛠️ Option 3 — Custom Email View
Notification::send([ 'mail' => [ 'mail_to' => 'email@email.com', 'mail_to_users' => $users, 'subject' => 'Email Subject', 'view' => 'applications.agents.emails.withdrawal-notification', 'data' => (object)[ 'user_name' => 'Anik Da', 'amount' => 1000, 'submitted_by' => 'Lukmanul Hakim Hasibuan', 'status' => 'Pending', 'transaction_view_on' => route('customer.product'), ], ] ]);
✨ Option 4 — Using sendMail() Helper
Notification::sendMail([ 'mail_to' => 'email@email.com', 'mail_to_users' => $users, 'subject' => 'Withdrawal Notification', 'view' => 'applications.agents.emails.withdrawal-notification', 'data' => (object)[ 'user_name' => 'Anik Da', 'amount' => 1000, 'submitted_by' => 'Lukmanul Hakim Hasibuan', 'status' => 'Pending', 'transaction_view_on' => route('customer.product'), ], ]);
🔔 Push Notifications
🗄️ Step 1: Setup Database
php artisan notifications:table php artisan migrate
🚀 Option 1 — Using Notification::send()
Notification::send([ 'push' => [ 'sent_to_users' => $users, 'data' => [ 'booking_id' => 1, 'message' => 'Your booking has been confirmed.', ], ] ]);
🚀 Option 2 — Using Notification::sendPush()
Notification::sendPush([ 'sent_to_users' => $users, 'data' => [ 'booking_id' => 1, 'message' => 'Your booking has been confirmed.', ], ]);
Push Notification Drawer
1. Overview
The Push Notification Drawer is a slide-in panel that shows all recent notifications for the logged-in user.
- Opens from the right side of the screen.
- Can be toggled from the notification bell icon in the top bar.
- Shows unread and read notifications, grouped by time.
- Supports click actions (e.g., open related page, mark as read, etc.).
2. Demo Page URL
You can view the demo page here:
👉 URL: https://your-domain.com/nht-notifications
(Replace this with your actual domain name)
Example placeholder:
Header menu bell icon
Sidebar notification drawer
2.1 Closed State (Bell Icon with Badge)
Top Navigation Bar
┌─────────────────────────────────────────────────────────┐
│ Logo ... 🔔 (3) │
└─────────────────────────────────────────────────────────┘
🌍 Localization Support
Enable localized messages in .env:
MAIL_SUBJECT_LOCALIZE=true
Create translation files:
resources/lang/en/notification.php resources/lang/en/account_registration.php
Example:
Notification::send([ 'mail-template' => [ 'template' => ['registration', 'Subject'], ... ] ]); return [ 'registration' => 'Hello :cun, your account at :agn is ready. Login here: :url', ];
📨 Retrieve Notifications
Notification::get();
📡 API Reference
The package provides a JSON API for retrieving and managing notifications. These routes are protected by the auth:sanctum middleware and use the prefix /api/v1 (configurable in notification.php).
1. Notifications List
Retrieve a list of notifications for the authenticated user.
- Endpoint:
GET /api/v1/notifications/{date?} - URL Parameters:
date(optional): Filter notifications by a specific date (e.g.,2025-05-01).
- Query Parameters:
guard(optional): Specify an authentication guard.
- Response:
{
"result": 1,
"response": "Notifications list.",
"notifications": {
"all": [...],
"unread": [...]
}
}
2. Notification Statistics
Get counts and periodic statistics for notifications.
- Endpoint:
GET /api/v1/notification-statistics - Query Parameters:
guard(optional): Specify an authentication guard.
- Response:
{
"result": 1,
"response": "Notifications statistics.",
"data": {
"total_notifications": 45,
"unread_notifications": 12,
"read_notifications": 33,
"notifications_today": 5,
"notifications_this_week": 20,
"notifications_this_month": 45
}
}
3. Mark as Read
Mark a single notification or all notifications as read.
- Endpoint:
PUT /api/v1/notification/read/{item} - URL Parameters:
item: The UUID of the notification orallto mark all as read.
- Query Parameters:
guard(optional): Specify an authentication guard.
- Response:
{
"result": 1,
"response": 1,
"unread": 11
}
4. Delete Notification
Delete a single notification or the last batch of notifications.
- Endpoint:
DELETE /api/v1/notification/delete/{item} - URL Parameters:
item: The UUID of the notification orallto delete the latest notifications.
- Query Parameters:
guard(optional): Specify an authentication guard.
- Response:
{
"result": 1,
"response": 1,
"unread": 11
}
🧹 Uninstall Package
To completely remove:
php artisan nht-notification:remove // or php artisan nht-notification:remove --force
and then
composer remove nht/notification
💡 Tips & Notes
- Ensure queue worker is running:
php artisan queue:work
mail_to_usersaccepts anyUsermodel collection.phonemust follow E.164 international format (+60,+88, etc.).- You can combine SMS + Email + Push in a single call.
- Works perfectly with queued notifications.
🧬 Example: Combined Notification
Notification::send([ 'sms' => [ 'phone' => '+60135871622', 'message' => 'Account activated successfully.', ], 'mail' => [ 'mail_to' => 'email@email.com', 'subject' => 'Account Activated', 'view' => 'emails.account-activated', 'data' => (object)['user_name' => 'Lukmanul Hakim'], ], 'push' => [ 'sent_to_users' => $users, 'data' => [ 'title' => 'Welcome!', 'message' => 'Your account is ready to use.', ], ], ]);
🛠️ Troubleshooting
| ⚠️ Issue | 💡 Fix |
|---|---|
| Email not sending | Check .env mail configuration and queue connection |
| SMS not sending | Verify your SMS API credentials and gateway setup |
| Push not working | Ensure notifications table exists & Notifiable trait is used in User model |
route('login') undefined |
Ensure your web.php defines a named route for login |
🧭 License
Released under the MIT License.
© 2025 Nazmul Hasan
🧡 Built with passion for modern Laravel development.
nht/notification 适用场景与选型建议
nht/notification 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 298 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「email」 「sms」 「notification」 「laravel」 「push notification」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nht/notification 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nht/notification 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nht/notification 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
Simple ASCII output of array data
yii2-sms expand
统计信息
- 总下载量: 298
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-05
