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.
Installs: 79
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Language:Blade
pkg:composer/nht/notification
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0
README
Version: 1.8.6
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();
π§Ή 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.
