PHPackages                             codewiser/laravel-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. codewiser/laravel-notifications

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

codewiser/laravel-notifications
===============================

Laravel Notification helpers

v1.2.15(10mo ago)28113MITPHPPHP ^8.1

Since Sep 27Pushed 10mo ago2 watchersCompare

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

READMEChangelogDependencies (2)Versions (51)Used By (3)

Laravel Notifications
=====================

[](#laravel-notifications)

Provides Laravel Notification helpers.

It supports few types of notification messages: `mail`, `broadcast` and `database`. All of it implements one contract, so we could build all these messages as one.

`broadcast` and `database` messages got unified payload format: [Web Notification](https://developer.mozilla.org/en-US/docs/Web/API/Notification). This format is ready to implement on frontend.

Migrations
----------

[](#migrations)

Change `notifications.data` column to `json` type and create `notification_mention` table.

```
php artisan vendor:publish --provider="Codewiser\Notifications\NotificationsServiceProvider"

php artisan migrate
```

Message Contract
----------------

[](#message-contract)

All messages — `mail`, `broadcast` and `database` implements `MessageContract`, so we can build messages as one.

```
use Codewiser\Notifications\Contracts\MessageContract;
use Codewiser\Notifications\Messages\MailMessage;
use Codewiser\Notifications\Messages\BroadcastMessage;
use Codewiser\Notifications\Messages\DatabaseMessage;

class ReviewArticle extends \Illuminate\Notifications\Notification
{
    protected function build(MessageContract $message)
    {
        $message
            ->subject('Article Review')
            ->line('You need to review article.')
            ->action('Review', url('/article', [
                'article' => $this->article->getKey()
            ]))
            // Format as blockquote
            ->quotation('Silent is gold');
    }

    public function toMail(): MailMessage
    {
        return (new MailMessage)
            ->tap(fn($message) => $this->build($message))
            // Markdown table
            ->table(fn(MarkdownTable $table) => $table
                ->row(['Title 1', 'Title 2'])
                ->row([':---', '---:'])
                ->row(['Text 1', 'Text 2'])
            );
    }

    public function toBroadcast(): BroadcastMessage
    {
        return (new BroadcastMessage)
            ->tap(fn($message) => $this->build($message))
            // Remove action button
            ->withoutAction()
            // Keep notification on screen until user closes it
            ->requireInteraction()
            // Icon to display on notification
            ->icon('https://example.com/icon.svg');
            // etc
    }

    public function toDatabase(): DatabaseMessage
    {
        return (new DatabaseMessage)
            ->tap(fn($message) => $this->build($message))
            // Use level to order database notifications
            ->level('danger')
            // Create notification as already read
            ->silent();
    }

    public function toArray(): array
    {
        return $this->toDatabase()->toArray();
    }
}
```

Broadcast Message
-----------------

[](#broadcast-message)

`broadcast` message has payload in [Web Notification](https://developer.mozilla.org/en-US/docs/Web/API/Notification)format.

Database Message
----------------

[](#database-message)

`database` message (as a `broadcast`) has [Web Notification](https://developer.mozilla.org/en-US/docs/Web/API/Notification)payload.

> N.B.
> This package provides extended `DatabaseNotification` class. Be sure to override User::notifications() method.

```
use Codewiser\Notifications\Builders\NotificationBuilder;
use Codewiser\Notifications\Models\DatabaseNotification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;

class User extends Model
{
    public function notifications(): MorphMany|NotificationBuilder
    {
        return $this->morphMany(DatabaseNotification::class, 'notifiable');
    }
}
```

Custom `NotificationBuilder` allows to order notifications by priority, scope query by notifiable, by notification class or by mentioned objects (see below).

### Mentions

[](#mentions)

Mention is a relation between database notification and some model(s).

Let's say our app has a notification about new post comment.

```
use Codewiser\Notifications\Messages\DatabaseMessage;

class PostCommentNotification extends \Illuminate\Notifications\Notification
{
    public function __construct(public Comment $comment) {
        //
    }

    public function toDatabase($notifiable): DatabaseMessage
    {
        return (new DatabaseMessage)
            ->subject('New comment')
            ->bindTo($this->comment)
            ->bindTo($this->comment->post);
    }
}
```

If we bind post and comment models to a database notification, we may show a counter with unread notifications about this post to a user viewing a post. We may build a menu with unread notification counter, etc.

```
// Unread notifications about any post:
$request->user()->notifications()
    ->whereMentioned(\App\Models\Post::class)
    ->whereUnread()
    ->count();

// Unread notifications about comments to exact post:
$request->user()->notifications()
    ->whereMentioned([
        $post,
        \App\Models\Comment::class
    ])
    ->whereUnread()
    ->count();
```

Method `whereMentioned` arguments may be constrained with a callback:

```
$user->notifications()
    ->whereMentioned([
        $post,
        \App\Models\Comment::class => fn($builder) => $builder
            ->wherePast('published_at')
    ]);
```

In this example we will get only notifications that relates to exact post and to comments, that has `published_at` in the past.

### Persistent database notifications

[](#persistent-database-notifications)

Database notifications may be marked as persistent. Your application may restrict user tries to mark such notification as read. Application will mark notification as read automatically, then user reaches goals.

For example, notification invites user to review some article. The notification stays unread until user reviews the article. Then article is reviewed, the notification is not relevant anymore.

```
use Codewiser\Notifications\Messages\DatabaseMessage;
use Codewiser\Notifications\Models\DatabaseNotification;
use Codewiser\Notifications\Builders\NotificationBuilder;

// Send persistent notification with mentioned article.
class ReviewArticleNotification extends \Illuminate\Notifications\Notification
{
    public function toDatabase(): DatabaseMessage
    {
        return (new DatabaseMessage)
            ->subject('Review article')
            ->action('Review', route('article.show', $this->article))
            ->persistent('You must review the article')
            ->bindTo($this->article);
    }
}

// Get unread notifications about an article
$article->mentions()
    ->where(fn (NotificationBuilder $builder) => $builder
        ->whereNotifiable($user)
        ->whereUnread()
    );

// Later... mark notification as read if article was reviewed.
if ($article->wasReviewed()) {
    $user->notifications()
        ->whereType(ReviewArticleNotification::class)
        ->whereMentioned($article)
        ->markAsRead();
}
```

Add `Mentionable` contract and `HasMentions` trait to every model, that may be mentioned:

```
use \Codewiser\Notifications\Contracts\Mentionable;
use \Codewiser\Notifications\Traits\HasMentions;
use \Illuminate\Database\Eloquent\Model;

class Article extends Model implements Mentionable
{
    // Provides mentions relation
    use HasMentions;
}
```

Previewing notifications
------------------------

[](#previewing-notifications)

You may preview not only [Mail](https://laravel.com/docs/10.x/notifications#previewing-mail-notifications), but Broadcast Notifications too — the same way.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance54

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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 ~13 days

Recently: every ~6 days

Total

50

Last Release

320d ago

Major Versions

v0.0.1 → v1.0.12023-09-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce23eaf7ae48d79d2b07efc83ff7cecb2664f428bd531b167b90169423f1453d?d=identicon)[Cellard](/maintainers/Cellard)

---

Top Contributors

[![Cellard](https://avatars.githubusercontent.com/u/1220316?v=4)](https://github.com/Cellard "Cellard (64 commits)")

---

Tags

laravelmentionsnotificationsweb-notifications

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codewiser-laravel-notifications/health.svg)

```
[![Health](https://phpackages.com/badges/codewiser-laravel-notifications/health.svg)](https://phpackages.com/packages/codewiser-laravel-notifications)
```

###  Alternatives

[spatie/laravel-failed-job-monitor

Get notified when a queued job fails

1.0k2.6M4](/packages/spatie-laravel-failed-job-monitor)[vemcogroup/laravel-sparkpost-driver

SparkPost driver to use with Laravel 6.x|7.x|8.x|9.x|10.x

421.7M1](/packages/vemcogroup-laravel-sparkpost-driver)[spatie/mailcoach

Self-host Mailcoach

4007.0k](/packages/spatie-mailcoach)[synergitech/laravel-postal

This library integrates Postal with the standard Laravel mail framework.

38107.1k](/packages/synergitech-laravel-postal)[motomedialab/smtp2go

Send emails via API using the first-class email courier SMTP2Go

1316.3k](/packages/motomedialab-smtp2go)

PHPackages © 2026

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