定制 saurabhpunia/notifyx 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

saurabhpunia/notifyx

Composer 安装命令:

composer require saurabhpunia/notifyx

包简介

A powerful Laravel package to provide a frontend + backend in-app notification system for modern Laravel applications

README 文档

README

A simple and powerful notification system for Laravel applications. Send notifications to users and display them beautifully with real-time updates.

📋 What Does This Package Do?

  • 📧 Send Notifications: Easily send notifications to users
  • 🔔 Notification Bell: Shows unread count with a nice dropdown
  • 📱 Real-time Updates: Notifications appear instantly without page refresh
  • ⚙️ User Preferences: Let users choose how they want to receive notifications
  • 📄 Notification History: Full page showing all user notifications
  • 🏢 Multi-tenant Ready: Works with apps that have multiple tenants/teams

🎯 Quick Demo

After installation, you can send a notification like this:

// Send a simple notification
notify($user)
    ->title('Welcome!')
    ->with('Thanks for joining our platform')
    ->type('message')
    ->send();

And display notifications in your layout:

<!-- Add this to your layout -->
<livewire:notification-bell />

📦 Installation

Step 1: Install the Package

composer require saurabhpunia/notifyx

Step 2: Publish and Run Migrations

php artisan vendor:publish --tag="notifyx-migrations"
php artisan migrate

Step 3: Publish Configuration

php artisan vendor:publish --tag="notifyx-config"

Step 4: Add Trait to User Model

Open your app/Models/User.php file and add the trait:

<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Notifyx\Concerns\HasNotifyx;

class User extends Authenticatable
{
    use HasNotifyx; // Add this line
    
    // ... rest of your User model
}

Step 5: Add to Your Layout

Add the notification bell to your main layout file:

<!-- In your layout file (e.g., resources/views/layouts/app.blade.php) -->
<div class="header">
    <!-- Your existing header content -->
    
    <!-- Add the notification bell -->
    <livewire:notification-bell />
</div>

⚙️ Configuration

Basic Setup

The package comes with sensible defaults. You can customize notification types in config/notifyx.php:

'types' => [
    'message' => [
        'label' => 'Messages',
        'icon' => 'heroicon-o-chat-bubble-left-right',
        'color' => 'blue'
    ],
    'system' => [
        'label' => 'System Updates',
        'icon' => 'heroicon-o-cog-6-tooth',
        'color' => 'gray'
    ],
    'billing' => [
        'label' => 'Billing',
        'icon' => 'heroicon-o-currency-dollar',
        'color' => 'green'
    ],
],

Multi-tenant Applications

If your app has multiple tenants/teams, enable multi-tenancy:

// config/notifyx.php

'multitenant' => true,
'tenant_resolver' => fn() => auth()->user()->current_team_id,

🚀 How to Use

Sending Notifications

Simple Notification

notify($user)
    ->with('Your order has been shipped!')
    ->send();

Notification with Title

notify($user)
    ->title('Order Update')
    ->with('Your order #12345 has been shipped and will arrive tomorrow.')
    ->send();

Notification with Type

notify($user)
    ->title('Payment Received')
    ->with('We received your payment of $99.99')
    ->type('billing')
    ->send();

Notification with Action Button

notify($user)
    ->title('New Message')
    ->with('You have a new message from John')
    ->type('message')
    ->action('/messages', 'View Message')
    ->send();

Notification via Multiple Channels

notify($user)
    ->title('Welcome!')
    ->with('Thanks for joining our platform')
    ->type('message')
    ->via(['database', 'mail', 'broadcast']) // Send via multiple channels
    ->send();

Using the Facade

You can also use the Notifyx facade:

use Notifyx\Facades\Notifyx;

Notifyx::to($user)
    ->title('Hello!')
    ->with('This is a test notification')
    ->send();

Display Components

Notification Bell (with dropdown)

<livewire:notification-bell />

This shows a bell icon with unread count and dropdown with recent notifications.

Full Notification Page

Create a route and view for the full notification page:

// routes/web.php
Route::get('/notifications', function() {
    return view('notifications');
})->name('notifications.index');
<!-- resources/views/notifications.blade.php -->
@extends('layouts.app')

@section('content')
    <livewire:notification-page />
@endsection

User Preferences Page

Let users customize their notification preferences:

<!-- resources/views/notification-preferences.blade.php -->
@extends('layouts.app')

@section('content')
    <livewire:notification-preferences />
@endsection

📱 Frontend Features

Real-time Updates

If you have Laravel Echo setup for broadcasting, notifications will appear in real-time without page refresh.

SPA-like Experience

All interactions (marking as read, deleting, etc.) happen without page reloads using Livewire.

User Preferences

Users can control:

  • Which notification types they want to receive
  • Which channels (email, browser, etc.) to use for each type
  • Enable/disable notifications entirely

🎨 Customization

Custom Views

Publish the views to customize the appearance:

php artisan vendor:publish --tag="notifyx-views"

Views will be published to resources/views/vendor/notifyx/.

Custom Notification Types

Add your own notification types in the config:

'types' => [
    'order' => [
        'label' => 'Order Updates',
        'icon' => 'heroicon-o-shopping-bag',
        'color' => 'purple'
    ],
    'friend_request' => [
        'label' => 'Friend Requests',
        'icon' => 'heroicon-o-user-plus',
        'color' => 'pink'
    ],
],

🔧 Advanced Usage

Get User Notifications

// Get recent notifications
$notifications = $user->getNotifications(10);

// Get paginated notifications
$notifications = $user->getPaginatedNotifications(15);

// Get unread count
$unreadCount = $user->getUnreadCount();

// Mark notification as read
$user->markNotificationAsRead($notificationId);

// Mark all as read
$user->markAllNotificationsAsRead();

Check User Preferences

// Check if user has enabled email notifications for billing
if ($user->hasEnabledNotification('billing', 'mail')) {
    // Send billing notification via email
}

📊 Database Tables

The package creates these tables:

  • notifications - Stores all notifications (Laravel's default)
  • notification_preferences - Stores user preferences for notification types/channels

🔍 Troubleshooting

Notifications Not Appearing

  1. Check if the trait is added to your User model
  2. Make sure migrations ran with php artisan migrate
  3. Clear cache with php artisan config:clear

Real-time Not Working

  1. Setup Laravel Echo for broadcasting
  2. Configure broadcasting driver (Pusher, Redis, etc.)
  3. Check broadcast channel permissions

Styling Issues

  1. Make sure Tailwind CSS is included in your project
  2. Publish views and customize if needed
  3. Check for CSS conflicts with your existing styles

📝 Requirements

  • PHP: 8.2 or higher
  • Laravel: 10.0, 11.0, or 12.0
  • Livewire: 3.0 or higher

🤝 Support

For issues or questions:

  1. Check the troubleshooting section above
  2. Create an issue if you find a bug

📄 License

This package is open-source software licensed under the MIT license.

🎉 That's It!

You now have a complete notification system in your Laravel app. Users can receive notifications, view them in a beautiful interface, and customize their preferences. The system works great for both simple websites and complex multi-tenant applications.

Happy coding! 🚀

saurabhpunia/notifyx 适用场景与选型建议

saurabhpunia/notifyx 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「real-time」 「notifications」 「laravel」 「livewire」 「in-app」 「notifyx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 saurabhpunia/notifyx 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 saurabhpunia/notifyx 我们能提供哪些服务?
定制开发 / 二次开发

基于 saurabhpunia/notifyx 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-22