kaveh / notification-service
Installs: 14
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/kaveh/notification-service
Requires
- php: ^8.3
- illuminate/notifications: *
- laravel/framework: *
README
A customizable notification package for Laravel.
Installation
Run the following command to install the package:
composer require kaveh/notification-service
Configuration
-
Register the Service Provider
Add the following line tobootstrap/providers.php:Kaveh\NotificationService\NotificationServiceProvider::class,
-
Update
composer.json
Add the following to theautoloadsection:"autoload": { "psr-4": { "Kaveh\\NotificationService\\": "vendor/kaveh/notification-service/src/" } }
Then, run:
composer dump-autoload
-
Migrate Notification Tables
Run the following command to create necessary database tables:php artisan notification:migrate
-
Extend the User Model
Replace the default LaravelAuthenticatableimport in yourUsermodel:Before:
use Illuminate\Foundation\Auth\User as Authenticatable;
After:
use Kaveh\NotificationService\Abstracts\Authenticatable;
And add this method in your model:
public function getId() { return $this->id; }
-
Notification Configuration
- Notification Type: Define the notification type, e.g.,
user_login,order_created, etc. - Notification Channel: Specify the notification delivery method:
email,sms,in-app, etc. - Notification Preferences:
We recommend using an event-listener to automatically set user notification preferences upon registration. This determines whether a user has granted permission for notifications.
- Notification Type: Define the notification type, e.g.,
Usage
Create a New Notification
Run the following command to generate a notification class:
php artisan make:notification-service {name}
Send a Notification
To send a notification, use:
NotificationService::sendNotification(notificationClass, UserModel, NotificationType, ?array data = []);
Enjoy using Laravel Notification Service! 🚀