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

v1.8.7 2025-12-28 08:51 UTC

This package is auto-updated.

Last update: 2025-12-28 08:52:47 UTC


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

Header menu bell icon

Sidebar notification drawer

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_users accepts any User model collection.
  • phone must 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.