PHPackages                             mhd-elawi/notification - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. mhd-elawi/notification

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

mhd-elawi/notification
======================

A notification package for Laravel

v1.0.2(1y ago)044MITPHPPHP ^8.0

Since Feb 20Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/MohamadElawi/notification)[ Packagist](https://packagist.org/packages/mhd-elawi/notification)[ RSS](/packages/mhd-elawi-notification/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (3)Used By (0)

Notification Package
====================

[](#notification-package)

Table of Contents
-----------------

[](#table-of-contents)

1. [Introduction](#introduction)
2. [Features](#features)
3. [Installation](#installation)
    - [Install the Package](#install-the-package)
    - [Publish Configuration and Migrations](#publish-configuration-and-migrations)
    - [Run Migrations](#run-migrations)
4. [Configuration](#configuration)
    - [Default Language](#default-language)
    - [Supported Languages](#supported-languages)
    - [Save Notifications](#save-notifications)

- [Firebase Configuration](#firebase-configuration)

5. [Usage](#usage)
    - [Sending Notifications](#sending-notifications)
    - - [Implementing HasNotification](#implementing-hasnotification)
    - [Disabling Persistence](#disabling-persistence)
    - [Disabling Notification](#disabling-notification)
    - [Advanced Configuration](#advanced-configuration)
6. [Contributing](#contributing)

---

Introduction
------------

[](#introduction)

The **Notification Package** is a Laravel package designed for managing multi-language notifications with support for:

- **Database persistence**: Save notifications for future reference.
- **Firebase Cloud Messaging (FCM)**: Send push notifications to mobile devices.
- **Multi-language support**: Easily translate notification content into multiple languages.

---

Features
--------

[](#features)

- Multi-language notifications
- Database persistence for auditability
- Integration with Firebase for push notifications
- Batch processing for scalable notifications
- Flexible configuration

---

Installation
------------

[](#installation)

### Install the Package

[](#install-the-package)

Run the following command:

```
composer require mhd-elawi/notification
```

### Publish Configuration and Migrations

[](#publish-configuration-and-migrations)

#### Publish Configuration File

[](#publish-configuration-file)

```
php artisan vendor:publish --tag=config
```

*Publishes the configuration file to **`config/notification.php`**.*

#### Publish Migrations

[](#publish-migrations)

```
php artisan vendor:publish --tag=migration
```

*Publishes the migration files to **`database/migrations`**.*

### Run Migrations

[](#run-migrations)

Run the migrations:

```
php artisan migrate
```

---

Configuration
-------------

[](#configuration)

### Default Language

[](#default-language)

Set the default language for notifications:

```
'default_language' => 'en',
```

If a language is not specified for a notification, it will fall back to this language.

### Supported Languages

[](#supported-languages)

Define the list of supported languages:

```
'languages' => ['en', 'ar', 'de', 'fr'],
```

### Save Notifications

[](#save-notifications)

By default, notifications are saved to the database:

```
'save_notifications' => true, // Set false to disable
```

### Firebase Configuration

[](#firebase-configuration)

Firebase configuration is optional. If using Firebase, configure the following:

#### Firebase Credentials

[](#firebase-credentials)

Set the path to the service account credentials in the `.env` file:

```
GOOGLE_APPLICATION_CREDENTIALS=storage/app/firebase-credentials.json
```

#### Firebase Project ID

[](#firebase-project-id)

Set the Firebase Project ID in the `.env` file:

```
FIREBASE_PROJECT_ID=your-project-id
```

#### Enable FCM

[](#enable-fcm)

Enable Firebase notifications in the configuration file:

```
'send_notifications' => true,
```

---

Usage
-----

[](#usage)

### Sending Notifications

[](#sending-notifications)

#### Single User Notification

[](#single-user-notification)

```
use MhdElawi\Notification\Utils\Notification;

Notification::for($user)
    ->setTitle('Hello, World!')
    ->setBody('This is a test notification.')
    ->send();
```

#### Multi-Language Notification

[](#multi-language-notification)

```
Notification::for($user)
    ->setTitle('Bonjour, Monde!', 'fr')
    ->setBody('Ceci est une notification de test.', 'fr')
    ->send();
```

#### Multi-Language Notifications :

[](#multi-language-notifications-)

```
    Notification::for($user)
    ->setTitleWithTranslation('notification.title', ['name' => $user->name])
    ->setBodyWithTranslation('notification.body', ['name' => $user->name])
    ->send();
```

#### Batch Notification

[](#batch-notification)

```
Notification::for($users)
    ->setTitle('Batch Notification')
    ->setBody('This notification is sent to multiple users.')
    ->send();
```

#### Notification with Related Data

[](#notification-with-related-data)

The related model in notifications allows associating a notification with a specific entity (e.g., a Post, Order, or Comment). This is achieved through a morph relationship in the notification model. When sending a notification, the related model's type (related\_type) and ID (related\_id) are included in the Firebase notification payload, allowing the frontend to handle and display notifications dynamically.

How It Works: Morph Relationship in Notification Model The notification system supports polymorphic relations, meaning a notification can be associated with any model (e.g., Post, Order, User).

Sending Related Model in Firebase Payload

When a related model is assigned, its model type and model ID are sent as part of the Firebase notification payload. This allows the frontend to recognize which entity the notification refers to and navigate users to the appropriate screen.

```
$relatedModel = Post::query()->first();

Notification::for($user, $relatedModel)
    ->setTitle('New Comment on Your Post')
    ->setBody('Someone has commented on your post.')
    ->setIcon('comment-icon')
    ->send();
```

Alternatively, you can use setRelatedModel() to assign the related model separately:

```
$relatedModel = Post::query()->first();

Notification::for($user)
->setRelatedModel($relatedModel) // Set the related model explicitly
->setTitle('New Comment on Your Post')
->setBody('Someone has commented on your post.')
->setIcon('comment-icon')
->send();
```

#### Notification with Extra Fields

[](#notification-with-extra-fields)

Set extra fields for the notification. like (Image, Color, Sound, Tag)

```
Notification::for($user)
    ->setTitle('New Comment on Your Post')
    ->setBody('Someone has commented on your post.')
    ->setIcon('comment-icon')
    ->setExtraFields(['sound' => 'something'])
    ->send();
```

---

### Implementing HasNotification

[](#implementing-hasnotification)

If using Firebase ensure your Recipient model implements the `HasNotification` interface:

```
use MhdElawi\Notification\Contracts\HasNotification;

class User extends Authenticatable implements HasNotification
{
    public function getDeviceTokens(): array
    {
        return $this->device_tokens ?? [];
    }
}
```

---

### Disabling Persistence

[](#disabling-persistence)

#### Disable in Configuration

[](#disable-in-configuration)

```
'save_notifications' => false,
```

#### Disable Per Notification

[](#disable-per-notification)

```
Notification::for($user)
    ->setTitle('Title')
    ->setBody('Body')
    ->send(false);
```

---

### Disable Sending Notification

[](#disable-sending-notification)

You can disable notifications for a specific notification or globally.

#### Disable in Configuration

[](#disable-in-configuration-1)

```
'send_notifications' => false,
```

#### Disable for a Specific Notification

[](#disable-for-a-specific-notification)

Use `disableSendNotification()` to prevent sending this specific notification.

```
Notification::for($users)
    ->setTitle('Hello, World!')
    ->setBody('This is a test notification.')
    ->disableSendNotification()
    ->send();
```

### Advanced Configuration

[](#advanced-configuration)

#### Batch Processing

[](#batch-processing)

#### Customize Table Names

[](#customize-table-names)

Update `table_names` in the configuration file to match your database schema.

---

Contributing
------------

[](#contributing)

1. Fork the repository.
2. Create a new branch for your feature or bug fix.
3. Submit a pull request with a detailed description of your changes.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance65

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

497d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b65e8a8e29d59dd22e8ea280879f337cd8a3e8e58ff67d43749cdacc021a7b7?d=identicon)[mohamad\_elawi](/maintainers/mohamad_elawi)

---

Top Contributors

[![MohamadElawi](https://avatars.githubusercontent.com/u/84589464?v=4)](https://github.com/MohamadElawi "MohamadElawi (7 commits)")

### Embed Badge

![Health badge](/badges/mhd-elawi-notification/health.svg)

```
[![Health](https://phpackages.com/badges/mhd-elawi-notification/health.svg)](https://phpackages.com/packages/mhd-elawi-notification)
```

###  Alternatives

[propaganistas/laravel-disposable-email

Disposable email validator

6023.0M7](/packages/propaganistas-laravel-disposable-email)[illuminate/mail

The Illuminate Mail package.

5910.6M499](/packages/illuminate-mail)[illuminate/notifications

The Illuminate Notifications package.

513.1M1.1k](/packages/illuminate-notifications)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
