amjitk/laravel-global-notification

A comprehensive notification system for Laravel with CMS and automated triggers.

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Language:Blade

pkg:composer/amjitk/laravel-global-notification

1.3.0 2025-12-19 05:20 UTC

This package is auto-updated.

Last update: 2025-12-19 05:23:01 UTC


README

Global Notification Logo

Laravel Global Notification

A comprehensive notification system for Laravel applications. This package allows you to manage notification types and templates via a CMS and automatically trigger them based on system events.

Features

  • CMS Interface: Manage notification types and templates (Email, Database, SMS, etc.).
  • Multi-Channel Support: Configure different templates for different channels for the same event.
  • Auto-Triggering: Automatically fire notifications on Eloquent model events (created, updated, etc.).
  • User Notification Center: Built-in UI for users to view and manage their in-app notifications.
  • Dynamic Content: Use placeholders like {{name}} in your templates.

Installation

  1. Install the package via Composer:

    composer require amjitk/laravel-global-notification

    Note: If testing locally without Packagist, configure your composer.json repositories to point to the local path.

  2. Run Migrations:

    php artisan migrate
  3. (Optional) Publish Configuration and Assets:

    php artisan vendor:publish --tag=global-notification-config
    php artisan vendor:publish --tag=global-notification-views

Configuration

The configuration file config/global-notification.php allows you to customize:

  • Channels: Enabled channels (default: mail, database).
  • Route Prefix: URL prefix for the package routes (default: global-notification).
  • Middleware: Middleware for admin routes. Configurable via .env:
    GLOBAL_NOTIFICATION_AUTH_ENABLED=true # Set to false to disable authentication

Usage

1. Admin - Manage Notifications

Visit /global-notification/notification-types to create new Notification Types (e.g., order_placed). Inside a Type, create Templates for each channel.

2. Triggering Notifications

Manual Trigger

Use the NotificationService to send a notification programmatically:

use AmjitK\GlobalNotification\Services\NotificationService;

$service = new NotificationService();
$service->send('order_placed', $user, ['order_id' => 123, 'amount' => '$50']);

Automatic Trigger (Model Events)

Add the AutoNotifyTrait to your Eloquent model:

use AmjitK\GlobalNotification\Traits\AutoNotifyTrait;

class Order extends Model
{
    use AutoNotifyTrait;

    // Map system events to Notification Type keys
    public $notificationRules = [
        'created' => 'order_placed',   // Fires 'order_placed' when Order is created
        'updated' => 'order_updated',  // Fires 'order_updated' when Order is updated
    ];
}

3. Notification Logs

View all system notifications at: /global-notification/logs

This page displays a global log of all notifications triggered in the system.

Testing

To run the package tests:

composer install
vendor/bin/phpunit