shufflingpixels/laravel-notification-action 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

shufflingpixels/laravel-notification-action

Composer 安装命令:

composer require shufflingpixels/laravel-notification-action

包简介

Adds actionable endpoints for Laravel database notifications.

README 文档

README

Adds simple, callable endpoints for Laravel database notifications. Define an action handler class, attach it to a notification via an attribute, and the package wires a /notification-action/{notification}/{action} route that executes the handler, optionally marking the notification as read.

Requirements

  • PHP 8.2+
  • Laravel 10, 11, or 12

Installation

composer require shufflingpixels/laravel-notification-action

How it works

  1. Annotate your notification with the #[Action(...)] attribute, pointing to an action handler class.
  2. Implement public methods on the handler; method names become callable actions.
  3. The package route resolves the handler, runs the requested method with the DatabaseNotification model, and returns its HTTP response.
  4. Returning ShufflingPixels\NotificationAction\Http\Response::markAsRead() marks the notification as read inside the transaction.

Example

use Illuminate\Notifications\Notification;
use ShufflingPixels\NotificationAction\Attributes\Action;
use ShufflingPixels\NotificationAction\Http\Response;

#[Action(MyNotificationActions::class)]
class InvoicePaidNotification extends Notification {}

class MyNotificationActions
{
    public function acknowledge(DatabaseNotification $notification): Response
    {
        // Do any side effects you need...
        return Response::markAsRead(); // returns 200 and marks as read if needed
    }
}

Call it from the browser or an email button:

GET /notification-action/{notification-uuid}/acknowledge

Configuration

Publish the config to tweak prefix or middleware:

php artisan vendor:publish --tag=notification-action-config

Default values:

return [
    'prefix' => 'notification-action',
    'middleware' => ['web', 'auth'],
];

Routing

The package registers:

GET {prefix}/{notification}/{action}  -> NotificationActionController

Route model binding resolves the DatabaseNotification instance by ID. Missing handlers or methods return 404.

Testing

vendor/bin/phpunit

License

AGPL-3.0-or-later

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: AGPL-3.0-or-later
  • 更新时间: 2025-12-01