PHPackages                             toneflix-code/approvable-notifications - 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. toneflix-code/approvable-notifications

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

toneflix-code/approvable-notifications
======================================

A Laravel package to handle database notifications that require user interactions

1.1.0(1y ago)020[5 PRs](https://github.com/toneflix/laravel-approvable-notifications/pulls)MITPHPPHP ^8.1|^8.2|^8.3CI passing

Since Jun 11Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/toneflix/laravel-approvable-notifications)[ Packagist](https://packagist.org/packages/toneflix-code/approvable-notifications)[ Docs](https://github.com/toneflix/laravel-approvable-notifications)[ RSS](/packages/toneflix-code-approvable-notifications/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (19)Used By (0)

Laravel Approvable Notifications
================================

[](#laravel-approvable-notifications)

[![Test & Lint](https://github.com/toneflix/laravel-approvable-notifications/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/toneflix/laravel-approvable-notifications/actions/workflows/run-tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/ad31fe397709c98f4d100cb84a267f5e83005fcfb0c200daea2774f4ab03d949/687474703a2f2f706f7365722e707567782e6f72672f746f6e65666c69782d636f64652f617070726f7661626c652d6e6f74696669636174696f6e732f76)](https://packagist.org/packages/toneflix-code/approvable-notifications) [![Total Downloads](https://camo.githubusercontent.com/ead1f2625be18cd354237c50ff87a3c9891f7a0bfb3d758cf420442cd4672088/687474703a2f2f706f7365722e707567782e6f72672f746f6e65666c69782d636f64652f617070726f7661626c652d6e6f74696669636174696f6e732f646f776e6c6f616473)](https://packagist.org/packages/toneflix-code/approvable-notifications) [![Latest Unstable Version](https://camo.githubusercontent.com/982cf4f5976debe97a8f005626c2d3668ab386857c2b5ddec1f77aca343b4aa8/687474703a2f2f706f7365722e707567782e6f72672f746f6e65666c69782d636f64652f617070726f7661626c652d6e6f74696669636174696f6e732f762f756e737461626c65)](https://packagist.org/packages/toneflix-code/approvable-notifications) [![License](https://camo.githubusercontent.com/0f9d3a06907b35c5ca050ae7340b6bf859446025bd4350a2b82225d355c837eb/687474703a2f2f706f7365722e707567782e6f72672f746f6e65666c69782d636f64652f617070726f7661626c652d6e6f74696669636174696f6e732f6c6963656e7365)](https://packagist.org/packages/toneflix-code/approvable-notifications) [![PHP Version Require](https://camo.githubusercontent.com/a80bf99d92bf8f4260b0c70f2fed4a0ecda6f10af91611c46c60d496a9834028/687474703a2f2f706f7365722e707567782e6f72672f746f6e65666c69782d636f64652f617070726f7661626c652d6e6f74696669636174696f6e732f726571756972652f706870)](https://packagist.org/packages/toneflix-code/approvable-notifications)[![codecov](https://camo.githubusercontent.com/40091fce241924716cd9ac2b9ccc080c48c43165e77be749af17b018700ccf7a/68747470733a2f2f636f6465636f762e696f2f67682f746f6e65666c69782f6c61726176656c2d617070726f7661626c652d6e6f74696669636174696f6e732f67726170682f62616467652e7376673f746f6b656e3d53486d317a594f674c48)](https://codecov.io/gh/toneflix/laravel-approvable-notifications)

Laravel Approvable Notifications adds to your project and handles the missing features of the Laravel notification system, the ability for users to interact with database notifications.

Use Cases
---------

[](#use-cases)

1. Friend Requests
2. Access Requests
3. Anything that requires a third party user to approve or reject.

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

[](#installation)

1. Install the package via composer:

    ```
    composer require toneflix-code/approvable-notifications
    ```
2. Publish resources (migrations and config files):

    ```
    php artisan vendor:publish --tag=approvable-notifications
    ```
3. Run the migrations with the following command:

    ```
    php artisan migrate
    ```
4. Done!

Package Discovery
-----------------

[](#package-discovery)

Laravel automatically discovers and publishes service providers but optionally after you have installed Laravel Fileable, open your Laravel config file config/app.php and add the following lines.

In the $providers array add the service providers for this package.

```
ToneflixCode\ApprovableNotifications\ApprovableNotificationsServiceProvider::class
```

Add the facade of this package to the $aliases array.

```
'ApprovableNotifications' => ToneflixCode\ApprovableNotifications\Facades\ApprovableNotifications::class
```

Usage
-----

[](#usage)

### The `SendsApprovableNotifications` Trait

[](#the-sendsapprovablenotifications-trait)

To be able to send notifications using Approvable Notifications add the `\ToneflixCode\ApprovableNotifications\Traits\SendsApprovableNotifications` trait to your model:

```
namespace App\Models;

use ToneflixCode\ApprovableNotifications\Traits\SendsApprovableNotifications;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use SendsApprovableNotifications;
}
```

That's it, we only have to use that trait in our model! Now your users may send approvable notifications.

> **Note:** you can use `SendsApprovableNotifications` trait on any model, it doesn't have to be the user model.

### The `HasApprovableNotifications` Trait

[](#the-hasapprovablenotifications-trait)

For a model to be able to receive notifications using Approvable Notifications you will also need to add the `\ToneflixCode\ApprovableNotifications\Traits\HasApprovableNotifications` trait to your model:

```
namespace App\Models;

use ToneflixCode\ApprovableNotifications\Traits\HasApprovableNotifications;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasApprovableNotifications;
}
```

Alternatively, if your model sends and recieves notifications, you can simply add only the `ApprovableNotifiable` trait on your model.

```
namespace App\Models;

use ToneflixCode\ApprovableNotifications\Traits\ApprovableNotifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use ApprovableNotifiable;
}
```

Now your model can both send and recieve approvable notifications.

### Sending notifications

[](#sending-notifications)

To send a notification, call the `sendApprovableNotification` method on the sender model, passing the `recipient` model, `title`, `message`, optional `data` and optional `actionable` model parameters.

```
$faker = \Faker\Factory::create();
$user = \App\Models\User::find(1);
$sender =\App\Models\User::find(12);
$actionable =\App\Models\User::find(5);

$notif = $sender->sendApprovableNotification(
    recipient: $user, // The recieving model
    title: $faker->sentence(4), // The title of the notification
    message: $faker->sentence(10), // The notification text message body
    data: ['icon' => 'fas fa-info'], // Any extra data you would like to store,
    actionable: $actionable, // Any model you would like to access or reference later during retrieval
);
```

### Accessing the Notifications

[](#accessing-the-notifications)

Once notifications are stored in the database, you need a convenient way to access them from your notifiable entities. The `ToneflixCode\ApprovableNotifications\Traits\HasApprovableNotifications` trait includes a `approvableNotifications` Eloquent relationship that returns the notifications for the entity. To fetch notifications, you may access this method like any other Eloquent relationship. By default, notifications will be sorted by the `created_at` timestamp with the most recent notifications at the beginning of the collection:

```
$user = App\Models\User::find(1);

foreach ($user->approvableNotifications as $notification) {
    echo $notification->title;
}
```

If you want to retrieve only the "unread" notifications, you may use the `unreadApprovableNotifications` relationship. Again, these notifications will be sorted by the `created_at` timestamp with the most recent notifications at the beginning of the collection:

```
$user = App\Models\User::find(1);

foreach ($user->unreadApprovableNotifications as $notification) {
    echo $notification->title;
}
```

Or to retrieve "approved" notifications

```
foreach ($user->approvedApprovableNotifications as $notification) {
    echo $notification->title;
}
```

#### Accessing the Notification Sender

[](#accessing-the-notification-sender)

You can access the `notifier` relationship on the notification instance to get the model that sent the notification.

```
foreach ($user->approvableNotifications as $notification) {
    $sender = $notification->notifier;
    echo $sender->name;
}
```

#### Accessing the Actionable model

[](#accessing-the-actionable-model)

If you added an actionable model when creating the notification, you can also access the `actionable` relationship on the notification instance.

```
foreach ($user->approvableNotifications as $notification) {
    $actionable = $notification->actionable;
    echo $actionable->title;
}
```

### Accessing sent Notifications

[](#accessing-sent-notifications)

Sent notifications also can also be accessed by the sender. The `ToneflixCode\ApprovableNotifications\Traits\SendsApprovableNotifications` trait includes a `approvableSentNotifications` Eloquent relationship that returns the notifications for the entity that sent them.

```
$user = App\Models\User::find(1);

foreach ($user->approvableSentNotifications as $notification) {
    echo $notification->title;
}
```

### Marking Notifications as Read

[](#marking-notifications-as-read)

Typically, you will want to mark a notification as "read" when a user views it. The `ToneflixCode\ApprovableNotifications\Traits\HasApprovableNotifications` trait provides a `markAsRead` method, which updates the `read_at` column on the notification's database record:

```
$user = App\Models\User::find(1);

foreach ($user->unreadApprovableNotifications as $notification) {
    echo $notification->markAsRead();
}
```

However, instead of looping through each notification, you may use the `markAsRead` method directly on a collection of notifications:

```
$user->unreadApprovableNotifications->markAsRead();
```

You may also use a mass-update query to mark all of the notifications as read without retrieving them from the database:

```
$user = App\Models\User::find(1);
$user->unreadApprovableNotifications()->update(['read_at' => now()]);
```

### Marking Notifications as Approved or Rejected

[](#marking-notifications-as-approved-or-rejected)

The primary purpose of this library is to allow you approve or reject actions associated with your models. The `ToneflixCode\ApprovableNotifications\Traits\HasApprovableNotifications` trait provides the `markAsApproved` and `markAsRejected` methods, which will update the `status` column on the notification's database record:

```
$user = App\Models\User::find(1);

foreach ($user->approvableNotifications as $notification) {
    echo $notification->markAsApproved();
}
```

```
$user = App\Models\User::find(1);

foreach ($user->approvableNotifications as $notification) {
    echo $notification->markAsRejected();
}
```

However, instead of looping through each notification, you may use the `markAsApproved` and `markAsRejected` methods directly on a collection of notifications:

```
$user->approvableNotifications->markAsApproved();
```

```
$user->approvableNotifications->markAsRejected();
```

### Deleting Notifications

[](#deleting-notifications)

You may delete the notifications to remove them from the table entirely:

```
$user->notifications()->delete();
```

### Events and Callback

[](#events-and-callback)

#### New Notification

[](#new-notification)

When a new notification is created, we dispatch the `ToneflixCode\ApprovableNotifications\Events\ApprovableNotificationCreated` event which you can listen to and perform further actions if required, the event will contain the associated `notification` model.

Alternattively, you can also implement the `newNotificationCallback` methods on your `SendsApprovableNotifications` entity, which will be called whenever a new notification is created and will provided with the associated `$notification` model as the first and only parameter.

```
namespace App\Models;

use ToneflixCode\ApprovableNotifications\Traits\SendsApprovableNotifications;
use Illuminate\Foundation\Auth\User as Authenticatable;
use ToneflixCode\ApprovableNotifications\Models\Notification;

class User extends Authenticatable
{
    use SendsApprovableNotifications;

    public function newNotificationCallback(Notification $notification) {
        // Perform any other actions here when a notification is created
    }
}
```

#### Notification Updates

[](#notification-updates)

When a notification is interacted with or updated, we dispatch the `ToneflixCode\ApprovableNotifications\Events\ApprovableNotificationUpdated` event which you can listen to and perform further actions if required, the event will contain the associated `notification` model.

Alternattively, you can also implement the `approvedNotificationCallback` and the `rejectedNotificationCallback` methods on your `HasApprovableNotifications` entity, both of which will be called at the appropriete time as the names imply and will provided with the associated `$notification` model as the first and only parameter.

```
namespace App\Models;

use ToneflixCode\ApprovableNotifications\Traits\HasApprovableNotifications;
use Illuminate\Foundation\Auth\User as Authenticatable;
use ToneflixCode\ApprovableNotifications\Models\Notification;

class User extends Authenticatable
{
    use HasApprovableNotifications;

    public function approvedNotificationCallback(Notification $notification) {
        // Perform any other actions here when a notification is approved
    }

    public function rejectedNotificationCallback(Notification $notification) {
        // Perform any other actions here when a notification is rejected
    }
}
```

### Exceptions

[](#exceptions)

When you attempt to send a notification to an invalid model (a model that does not use the `ToneflixCode\ApprovableNotifications\Traits\HasApprovableNotifications` trait), the library throws the `ToneflixCode\ApprovableNotifications\Exception\InvalidRecipientExeption` exception.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Toneflix Code](https://github.com/toneflix)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance66

Regular maintenance activity

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 71.4% 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 ~7 days

Recently: every ~18 days

Total

11

Last Release

630d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4638f9de973d94753ebff641af3009e1049064f9a6bd76fe87e58d0d8ddd7ca7?d=identicon)[3m1n3nc3](/maintainers/3m1n3nc3)

---

Top Contributors

[![3m1n3nc3](https://avatars.githubusercontent.com/u/52163001?v=4)](https://github.com/3m1n3nc3 "3m1n3nc3 (40 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

toneflix-codeapprovable-notifications

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/toneflix-code-approvable-notifications/health.svg)

```
[![Health](https://phpackages.com/badges/toneflix-code-approvable-notifications/health.svg)](https://phpackages.com/packages/toneflix-code-approvable-notifications)
```

###  Alternatives

[mckenziearts/laravel-notify

Flexible flash notifications for Laravel

1.7k1.1M5](/packages/mckenziearts-laravel-notify)[s-ichikawa/laravel-sendgrid-driver

This library adds a 'sendgrid' mail driver to Laravel.

4139.3M1](/packages/s-ichikawa-laravel-sendgrid-driver)[laravel-notification-channels/apn

Apple APN Push Notification Channel

2021.9M4](/packages/laravel-notification-channels-apn)[laravel-notification-channels/microsoft-teams

A Laravel Notification Channel for Microsoft Teams

1603.0M7](/packages/laravel-notification-channels-microsoft-teams)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)[illuminate/mail

The Illuminate Mail package.

5910.1M391](/packages/illuminate-mail)

PHPackages © 2026

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