shufflingpixels / laravel-notification-action
Adds actionable endpoints for Laravel database notifications.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/shufflingpixels/laravel-notification-action
Requires
- php: ^8.2
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/http: ^10.0|^11.0|^12.0
- illuminate/notifications: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.26
- orchestra/testbench: ^7.0|^8.0|^10.0
- phpunit/phpunit: ^10.5|^11.0|^12.0
This package is auto-updated.
Last update: 2025-12-01 22:04:35 UTC
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