Download the PHP package sysmatter/laravel-notification-preferences without Composer
On this page you can find all versions of the php package sysmatter/laravel-notification-preferences. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sysmatter/laravel-notification-preferences
More information about sysmatter/laravel-notification-preferences
Files in sysmatter/laravel-notification-preferences
Package laravel-notification-preferences
Short Description Manage and display user notification preferences in Laravel
License MIT
Homepage https://github.com/sysmatter/laravel-notification-preferences
Informations about the package laravel-notification-preferences
Laravel Notification Preferences Packaged Moved -> offload-project/laravel-notification-preferences
A Laravel package for managing user notification preferences with support for multiple channels, notification groups, and a structured table output for display.
Features
- ✅ User-specific notification preferences per channel
- ✅ Automatic channel filtering for all notifications
- ✅ Opt-in trait for granular control
- ✅ Notification grouping for organization
- ✅ Configurable default behaviors (opt-in/opt-out)
- ✅ Forced channels that cannot be disabled
- ✅ Structured table output for UI rendering
- ✅ Laravel 12 compatible
- ✅ PostgreSQL 18 support
Requirements
- PHP 8.2+
- Laravel 11+
- Any Laravel-supported database (PostgreSQL, MySQL, SQLite, etc.)
Installation
Publish the config and migrations:
Run migrations:
Uninstalling
To completely remove the package and its data:
Warning: The uninstall command permanently deletes all notification preferences. Make sure to back up your data if needed.
Configuration
Edit config/notification-preferences.php:
Usage
Add Trait to User Model
Option A: Automatic Filtering (Recommended)
All registered notifications in the config will automatically filter channels based on user preferences. No changes needed to your notification classes!
Option B: Explicit Control with Trait
For more control, use the ChecksNotificationPreferences trait in your notification:
Managing Preferences
Bulk Update Operations
The package provides convenient methods for bulk updating notification preferences, making it easy to implement "disable all emails" or "turn off marketing" features.
Available Bulk Methods
Disable/Enable All Notifications in a Group for a Channel
Turn off all marketing emails:
Turn on all system notifications for in-app:
Disable/Enable a Channel Across All Notifications
Turn off all email notifications:
Enable push notifications for everything:
Disable/Enable All Channels for a Notification Type
Turn off all channels for a specific notification:
Enable all channels for security alerts:
Return Values
All bulk methods return the count of preferences updated:
This is useful for providing user feedback:
Forced Channels are Skipped
Bulk operations automatically skip forced channels:
UI Implementation Examples
"Disable All Emails" Button
"Mute Marketing" Toggle
"Notification Type Master Toggle"
Direct Manager Access
You can also use the manager directly:
Building a Preferences UI
Here's a complete example of a preferences page controller:
Table Structure Output
The getNotificationPreferencesTable() method returns data structured for easy UI rendering:
API Endpoints Example
Create a controller to manage preferences:
Routes:
Frontend Example (Inertia/React 19)
Testing with Pest
Testing with Pest
The package includes a comprehensive test suite using Pest.
Test Structure
-
Unit Tests: Test individual components in isolation
NotificationPreferenceTest.php- Model testsNotificationPreferenceManagerTest.php- Manager logic testsPreferencesTableTest.php- Table structure testsHasNotificationPreferencesTest.php- Trait tests
- Feature Tests: Test integrated behavior
NotificationFilteringTest.php- Channel filtering testsDefaultPreferencesTest.php- Default behavior tests
Example Test
Advanced Features
Forced Channels
Prevent users from disabling critical notifications on certain channels:
Per-Channel Defaults
Set different defaults for each channel:
Cache Management
The package caches preferences for performance. Clear cache when needed:
Contributing
Please see CONTRIBUTING for details.
Security
Please review our security policy for reporting vulnerabilities.
Credits
License
MIT License. See LICENSE file for details.