PHPackages                             rezawikan/custom-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. rezawikan/custom-notifications

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

rezawikan/custom-notifications
==============================

Custom notifications for Laravel

03PHP

Since May 10Pushed 7y ago1 watchersCompare

[ Source](https://github.com/rezawikan/custom-notifications)[ Packagist](https://packagist.org/packages/rezawikan/custom-notifications)[ RSS](/packages/rezawikan-custom-notifications/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

custom-notifications
====================

[](#custom-notifications)

> Package for custom notification (DatabaseChannels) in Laravel.

This package help you to improve laravel notification in various types of model and class. Let's see how easily to setup.

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

[](#installation)

You can install the package via composer:

```
composer require rezawikan/custom-notifications
```

Usage
-----

[](#usage)

The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file:

```
'providers' => [
    // ...
    Rezawikan\CustomNotifications\CustomNotificationServiceProvider::class,
];
```

Migrate the database and create your first notification for use this package.

```
php artisan migrate

```

```
php artisan make:notification NotificationName

```

Use the custom database channel in notification. If you want to add additional method such us mail or SMS it's fine.

```
use Rezawikan\CustomNotifications\Notifications\Channels\DatabaseChannel;

/**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [
          DatabaseChannel::class
        ];

    }
```

Customize your representation array of the notification. You can add anything, according your data that your recieve on the construct method.

> - note that if you changes `toArray` function with another structure. You can restructure on database with `php artisan notifications:restructure`
>
> ```
> /**
>     * Get the array representation of the notification.
>     *
>     * @param  mixed  $notifiable
>     * @return array
>     */
>    public function toArray($notifiable)
>    {
>        return [
>            'comment' => [
>              'id'   => $this->comment->id,
>              'body' => $this->comment->body
>            ]
>        ];
>    }
> ```

Now, move to user model. You must the the relation to the notification table.

```
use Illuminate\Notifications\Notifiable;
use App\App\Notifications\Models\DatabaseNotification;

class User extends Authenticatable
{
  use Notifiable;

  /**
     * [posts description]
     * @return [type] [description]
     */
    public function notifications()
    {
        return $this->morphMany(DatabaseNotification::class, 'notifiable')->orderBy('created_at','desc');
    }
}
```

Then you can run and use it in your controller or routes.

```
  $user = User::find(1);
  $comment = Comment::find(1);

  $user->notify(new CommentCreated($comment));
```

Attribute
---------

[](#attribute)

There are attribute value on the $notification object. In this package, we have additional value.

```
$notification->models
$notification->type_class
```

Tips on the blade view
----------------------

[](#tips-on-the-blade-view)

Generate notification in controller. Make sure you have login to your app.

```
$notifications = $request->user()->notifications;
```

Create slot blade, put on the resources/notifications/notification.blade.php

```

{{ $slot }}
Mark as read

```

Create component blade, put on the resources/notifications/types/**name**.blade.php Name of file, must according to model name. In our example, we use model comment, you can add with other model.

```
@component('notifications/notification')
  {{ $notification->data->author->name }} posted comment
@endcomponent
```

On the index blade or that want to display the notifications list.

```
@foreach($notifications as $notification)
  @include('notifications/type/'. snake_case($notification->type), compact('notification'))
@endforeach
```

Meta
----

[](#meta)

Mochammad Rezza Wikandito – [@rezawikan](https://twitter.com/rezawikan) –

[https://github.com/rezawikan/custom-notifications](https://github.com/rezawikan/)

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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.

### Community

Maintainers

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

### Embed Badge

![Health badge](/badges/rezawikan-custom-notifications/health.svg)

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

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M227](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

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

PHPackages © 2026

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