amjitk/laravel-global-notification
最新稳定版本:1.3.0
Composer 安装命令:
composer require amjitk/laravel-global-notification
包简介
A comprehensive notification system for Laravel with CMS and automated triggers.
README 文档
README
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
-
Install the package via Composer:
composer require amjitk/laravel-global-notification
Note: If testing locally without Packagist, configure your
composer.jsonrepositories to point to the local path. -
Run Migrations:
php artisan migrate
-
(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
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-18
