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

This package is auto-updated.

Last update: 2025-06-17 06:16:48 UTC


README

A customizable notification package for Laravel.

Installation

Run the following command to install the package:

composer require kaveh/notification-service

Configuration

  1. Register the Service Provider
    Add the following line to bootstrap/providers.php:

    Kaveh\NotificationService\NotificationServiceProvider::class,
  2. Update composer.json
    Add the following to the autoload section:

    "autoload": {
        "psr-4": {
            "Kaveh\\NotificationService\\": "vendor/kaveh/notification-service/src/"
        }
    }

    Then, run:

    composer dump-autoload
  3. Migrate Notification Tables
    Run the following command to create necessary database tables:

    php artisan notification:migrate
  4. Extend the User Model
    Replace the default Laravel Authenticatable import in your User 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;
     }
  5. 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.

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! 🚀