PHPackages                             abather/model-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. abather/model-notification

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

abather/model-notification
==========================

Add notifications Template into Models

1.0.0(2y ago)0101[1 PRs](https://github.com/Abather/model-notification/pulls)MITPHPPHP ^8.1CI failing

Since Apr 25Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Abather/model-notification)[ Packagist](https://packagist.org/packages/abather/model-notification)[ Docs](https://github.com/abather/model-notification)[ GitHub Sponsors]()[ RSS](/packages/abather-model-notification/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

🔔 Model Notification
====================

[](#-model-notification)

[![Latest Version on Packagist](https://camo.githubusercontent.com/71dda26633ca34c038a3f79c66e4dcfb1ba93c5a6c30e72ac1dfd473676ba910/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616261746865722f6d6f64656c2d6e6f74696669636174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/abather/model-notification)[![Total Downloads](https://camo.githubusercontent.com/3c9176e9336b4906fe81f1f780f5c6ad6bc2fb7f3dda637b3c48c2d4a2798a81/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616261746865722f6d6f64656c2d6e6f74696669636174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/abather/model-notification)[![License](https://camo.githubusercontent.com/1a935f0b48d18e4f0f60b611e08f759438a18d514f1c7e6afaf7084c7425729d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616261746865722f6d6f64656c2d6e6f74696669636174696f6e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

**Stop hardcoding notification strings.** Model Notification gives you a powerful, database-driven way to manage dynamic notification templates for your Eloquent models.

Supports variable replacement, multi-language fallbacks, and file attachments—all with a fluent, developer-friendly API.

---

✨ Features
----------

[](#-features)

- 📝 **Dynamic Templates** - Manage templates in your database, not your code.
- 🔄 **Smart Variables** - Inject model attributes `[id]`, relationships `[user->name]`, and even method results `[total()]`.
- 🌍 **Localization** - Automatic language handling with fallback support.
- 📎 **Attachments** - Easily include files (like invoices or reports) in your messages.
- 💾 **Caching &amp; Performance** - Built-in caching for high-speed retrieval.
- ✅ **Validation** - Catch syntax errors before they reach your users.

---

🚀 Quick Start
-------------

[](#-quick-start)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require abather/model-notification
```

### 2. Publish Migrations

[](#2-publish-migrations)

```
php artisan vendor:publish --tag="model-notification-migrations"
php artisan migrate
```

### 3. Prepare Your Model

[](#3-prepare-your-model)

Add the `Notifier` trait and interface to any model you want to send notifications for (e.g., `Invoice`, `Order`, `User`).

```
use Abather\ModelNotification\Contracts\Notifier;
use Abather\ModelNotification\Notifier as NotifierTrait;
use Illuminate\Database\Eloquent\Model;

class Invoice extends Model implements Notifier
{
    use NotifierTrait;
}
```

### 4. Create &amp; Use a Template

[](#4-create--use-a-template)

```
// 1. Create a template (usually in a seeder or admin panel)
Invoice::makeTemplateMessage()
    ->key('invoice_paid')
    ->channel('email')
    ->lang('en')
    ->template('Hi [client->name], your payment of [formatted_amount] for invoice #[id] was received.')
    ->save();

// 2. Fetch the message for a specific invoice
$invoice = Invoice::find(1);
$message = $invoice->getTemplateMessageText('invoice_paid', 'en', 'email');

// Output: "Hi John Doe, your payment of $150.00 for invoice #1001 was received."
```

---

📚 Variable Syntax
-----------------

[](#-variable-syntax)

The real power lies in how you can use variables in your templates.

TypeSyntaxDescriptionExample**Attribute**`[column_name]`Value of a model column`Invoice #[id]`**Relationship**`[relation->col]`Value from a related model`Thanks, [user->name]`**Method**`[method()]`Result of a method call`Total: [calculateTotal()]`**File**`[file_path]`Link to an attached file`Download: [file_path]`> **Note:** You can customize the start (`[`) and end (`]`) delimiters in the config file.

---

🛠️ Advanced Usage
-----------------

[](#️-advanced-usage)

### Including Files

[](#including-files)

Need to send a PDF or image? Just chain `includeFile()` when creating the template.

```
Invoice::makeTemplateMessage()
    ->key('invoice_sent')
    ->template('Here is your invoice #[id].')
    ->includeFile() // save();

// Retrieve file URL later
$url = $invoice->getFile('invoice_sent', 'en', 'email');
```

### Extra Data (Prob)

[](#extra-data-prob)

Sometimes you need dynamic data that isn't on the model, like a custom subject line or icon.

```
Invoice::makeTemplateMessage()
    ->key('push_notification')
    ->template('New Order Received')
    ->prob([
        'title'   => 'Order #[id]',
        'icon'    => 'cart',
        'deep_link' => 'app://orders/[id]'
    ])
    ->save();

// Retrieve parsed data
$data = $invoice->getTemplateMessageProb('push_notification', 'en', 'push');
// Result: ['title' => 'Order #1001', 'icon' => 'cart', 'deep_link' => 'app://orders/1001']
```

⚙️ Configuration
----------------

[](#️-configuration)

Publish the config file to customize caching, validation rules, and strict mode settings.

```
php artisan vendor:publish --tag="model-notification-config"
```

Useful options:

- `fallback_lang`: Default language if the requested one is missing (default: `ar`).
- `max_depth`: Maximum depth for nested variable resolution (default: `10`).
- `strict_mode`: Throw exceptions if a variable is missing (default: `false`).
- `cache.ttl`: How long to cache templates (default: `24 hours`).

---

🧪 Testing
---------

[](#-testing)

We use **Pest** for testing. Run the suite to ensure everything is working correctly.

```
composer test
```

---

📄 License
---------

[](#-license)

The MIT License (MIT). See [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance56

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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

Unknown

Total

1

Last Release

752d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d032b178010eeffd089ecd6f75934079dc36d2d41328827f1d19c729572cbeb?d=identicon)[Abather](/maintainers/Abather)

---

Top Contributors

[![Abather](https://avatars.githubusercontent.com/u/18185658?v=4)](https://github.com/Abather "Abather (4 commits)")[![JoDeveloper](https://avatars.githubusercontent.com/u/18007194?v=4)](https://github.com/JoDeveloper "JoDeveloper (4 commits)")

---

Tags

laravelMohammed Sadiqmodel-notification

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/abather-model-notification/health.svg)

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

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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