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
- Annotate your notification with the
#[Action(...)]attribute, pointing to an action handler class. - Implement public methods on the handler; method names become callable actions.
- The package route resolves the handler, runs the requested method with the
DatabaseNotificationmodel, and returns its HTTP response. - 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
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2025-12-01