kaveh / notification-service
There is no license information available for the latest version (1.0.0) of this package.
1.0.0
2025-02-17 05:16 UTC
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 theautoload
section:"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 LaravelAuthenticatable
import in yourUser
model: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
! 🚀