Laravel notification manager

Overview

Laravel notification manager

Platform Latest Version on Packagist GitHub Workflow Status Check & fix styling GitHub GitHub all releases

In addition to Laravel’s default notifications, this package adds further attributes like seen_at, is_prioritised, is_muted, preview_type and alert_type. These attributes can be used to classify notifications for a better user experience. Furthermore, using this package you can manage subscriptions to certain notifications based on user preference, meaning that a user can specify whether or not to receive a certain notification type, channel or even a specific notification.

Features

  • Manage subscribers
  • Manage notification priorities
  • Manage muted notifications (mute, unmute)
  • Classifies notifications according to the way they appear
  • Classifies notifications according where they appear
  • Mark as seen

Installation

You can install the package via composer:

composer require rubik-llc/laravel-notification-manager

You can publish and run the migrations with:

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

You can publish the config file with:

php artisan vendor:publish --tag="notification-manager-config"

This is the contents of the published config file:

"database,broadcast", | */ 'channels' => "", ];">
return [

    /*
    |--------------------------------------------------------------------------
    | Subscribable notifications
    |--------------------------------------------------------------------------
    |
    | All notifications which we would like to be subscribable must be placed here.
    | If artisan command is used to create subscribable notification this will be autofilled
    |
    | Example:
    |   'subscribable_notifications' => [
    |       'order.accepted' => Rubik\NotificationManager\Tests\TestSupport\Notifications\OrderApprovedSubscribableNotification,
    |       'order.rejected' => Rubik\NotificationManager\Tests\TestSupport\Notifications\OrderRejectedSubscribableNotification,
    |   ],
    */

    'subscribable_notifications' => [

    ],

    /*
    |--------------------------------------------------------------------------
    | Channels
    |--------------------------------------------------------------------------
    |
    | All available channels must be placed here
    | A notification will be sent to all these channels if model is subscribed to all channel("*").
    | Example
    | 'channels' => "database,broadcast",
    |
    */

    'channels' => "",


];

Usage

  1. Use our “Notifiable” trait in all models you wish to send notifications(most cases Users)
    • This can be done by changing the import from “use Illuminate\Notifications\Notifiable;” to “use Rubik\NotificationManager\Traits\Notifiable;”, and also if not yet use the trait “use Notifiable”;. Your model should look like
  2. Use HasNotificationSubscription trait in all models you wish to send notifications
  3. Create subscribale notification by using “-s” flag in the default artisan command to create a notification.
  4. Add this notification to config file
php artisan make:notification SubscribaleNotification -s

From now on everything is the same as a normal notification. Below you can see how your Model and Notification should look like:

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Rubik\NotificationManager\Contracts\SubscribableNotificationContract;
use Rubik\NotificationManager\Traits\SubscribableNotification;

class TestNotification extends Notification implements SubscribableNotificationContract
{
    use Queueable, SubscribableNotification;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Subscribable type based on the name in config file
     *
     * @return string
     */
    public static function subscribableNotificationType(): string
    {
        return 'test';
    }


    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

If you want to convert a notification to a subscribable notification all you have to do is add SubscribaleNotification Contract and implement all methods required, and use SubscribaleNotification trait. Do not forget to add this notifion to your config. Your notification should look like:

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Rubik\NotificationManager\Contracts\SubscribableNotificationContract;
use Rubik\NotificationManager\Traits\SubscribableNotification;

class TestNotification extends Notification implements SubscribableNotificationContract
{
    use Queueable, SubscribableNotification;

    //Your code here

    /**
     * Subscribable type based on the name in config file
     *
     * @return string
     */
    public static function subscribableNotificationType(): string
    {
        return 'test';
    }
}

All changes will affect only future notifications, and if not specified different changes will affect the desired notification of the authenticated user. Will be explained below.

Subscribers/Unsubscribe

Subscribe to a notification:

NotificationManager::subscribe(OrderApprovedSubscribableNotification::class);

or:

OrderApprovedSubscribableNotification::subscribe();

Unsubscribe to a notification:

NotificationManager::unsubscribe(OrderApprovedSubscribableNotification::class);

or:

OrderApprovedSubscribableNotification::unsubscribe();

Subscribe a user to a notification:

NotificationManager::for(User::find(1))->subscribe(OrderApprovedSubscribableNotification::class);

Unsubscribe a user to a notification:

NotificationManager::for(User::find(1))->unsubscribe(OrderApprovedSubscribableNotification::class);

Subscribe to all notifications:

NotificationManager::subscribeAll();

Unsubscribe to all notifications:

NotificationManager::unsubscribeAll();

Subscribe a user to all notifications:

NotificationManager::for(User::find(1))->subscribeAll();

Unsubscribe a user to all notifications:

NotificationManager::for(User::find(1))->unsubscribeAll();

Send notification to all subscribers:

Instead of using:

Notification::send(User::subscribers()->get(),new OrderApprovedSubscribableNotification($payload));

Use:

OrderApprovedSubscribableNotification::sendToSubscribers($payload)

Everything passed to send to subscriber will be passed to notification constructor.

Priority

Set priority to a notification:

NotificationManager::prioritize(OrderApprovedSubscribableNotification::class);

or:

OrderApprovedSubscribableNotification::prioritize();

Unset priority to a notification:

NotificationManager::trivialize(OrderApprovedSubscribableNotification::class);

or:

OrderApprovedSubscribableNotification::trivialize();

Set priority to a notification as a user:

NotificationManager::for(User::find(1))->prioritize(OrderApprovedSubscribableNotification::class);

Unset priority to a notification as a user:

NotificationManager::for(User::find(1))->trivialize(OrderApprovedSubscribableNotification::class);

Mute

Mute a notification:

NotificationManager::mute(OrderApprovedSubscribableNotification::class);

or:

OrderApprovedSubscribableNotification::mute();

Unmute a notification:

NotificationManager::unmute(OrderApprovedSubscribableNotification::class);

or:

OrderApprovedSubscribableNotification::unmute();

Mute a notification for a user:

NotificationManager::for(User::find(1))->mute(OrderApprovedSubscribableNotification::class);

Unmute a notification for a user:

NotificationManager::for(User::find(1))->unmute(OrderApprovedSubscribableNotification::class);

Alert type

Set/update alert type:

NotificationManager::alertType(OrderApprovedSubscribableNotification::class, NotificationAlertType::BANNER);

or:

OrderApprovedSubscribableNotification::alertType(NotificationAlertType::BANNER);

Available alert types:

NotificationAlertType::NOTIFICATION_CENTER;
NotificationAlertType::BANNER;
NotificationAlertType::LOCK_SCREEN;

those are only values and in no way they represent a logic. You can use those values to classify notifications.

Preview type

Set/update preview type:

NotificationManager::previewType(OrderApprovedSubscribableNotification::class, NotificationPreviewType::ALWAYS);

or:

OrderApprovedSubscribableNotification::previewType(NotificationPreviewType::ALWAYS);

Available alert types:

NotificationPreviewType::ALWAYS;
NotificationPreviewType::WHEN_UNLOCKED;
NotificationPreviewType::NEVER;

Seen

Mark as seen

User::find(1)->notifications()->markAsSeen();

or:

DatabaseNotification::all()->markAsSeen();

or:

$user=User::find(1);

$user->unseenNotifications()->update(['seen_at' => now()]);

or:

$user = App\Models\User::find(1);
 
foreach ($user->unseenNotifications as $notification) {
    $notification->markAsSeen();
}

Mark as unseen

User::find(1)->notifications()->markAsUnseen();

or:

DatabaseNotification::all()->markAsUnseen();

or:

$user->seenNotifications()->update(['seen_at' => null]);

or:

$user = App\Models\User::find(1);
 
foreach ($user->seenNotifications as $notification) {
    $notification->markAsUnseen();
}

Get all seen notifications:

User::find(1)->seenNotifications();

Get all unseen notifications:

User::find(1)->unseenNotifications();

Get all prioritized notifications:

User::find(1)->prioritizedNotifications();

Get all trivialized notifications:

User::find(1)->trivializedNotifications();

Get all muted notifications:

User::find(1)->mutedNotifications();

Get all unmuted notifications:

User::find(1)->unmutedNotifications();

Get all notifications with alert type set to 'notification-center':

User::find(1)->alertNotificationCenterNotifications();

Get all notifications with alert type set to 'banner':

User::find(1)->alertBannerNotifications();

Get all notifications with alert type set to 'lock-screen':

User::find(1)->alertLockScreenNotifications();

Get all notifications with preview type set to 'always':

User::find(1)->previewAlwaysNotifications();

Get all notifications with preview type set to 'when-unlocked':

User::find(1)->previewWhenUnlockedNotifications();

Get all notifications with preview type set to 'never':

User::find(1)->previewNeverNotifications();

Check if a notification is seen:

User::find(1)->notifications()->first()->seen();

Check if a notification is unseen:

User::find(1)->notifications()->first()->unseen();

Check if a notification is prioritised:

User::find(1)->notifications()->first()->seen();

Check if a notification is trivialised:

User::find(1)->notifications()->first()->triavilized();

Check if a notification is muted:

User::find(1)->notifications()->first()->muted();

Check if a notification is unmuted:

User::find(1)->notifications()->first()->unmuted();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
Releases(v0.1.0)
Owner
Rubik
Rubik
@Authy notification channel for @Laravel, with the ability to send in-app, sms, and call verification tokens.

Authy Notification Channel for Laravel Authy notification channel for Laravel, with the ability to send in-app, sms, and call verification tokens. Tab

Laravel Notification Channels 57 Dec 19, 2022
Google Chat - Laravel Notification Channel

Google Chat - Laravel Notification Channel This package makes it easy to send notifications using Google Chat , (formerly known as Hangouts Chat) with

Laravel Notification Channels 36 Dec 6, 2022
Laravel SMS Notification Channel

Laravel SMS Notification Channel Installation composer require guangda/laravel-sms-notification-channel env 配置 SMS_PROVIDER=yunpian SMS_SIGNATURE=【签名

Guangda 6 Dec 29, 2021
A Toast notification library for the Laravel TALL stack.

A Toast notification library for the Laravel TALL stack. You can push notifications from the backend or frontend to render customizable toasts with almost zero footprint on the published CSS/JS ????

John F 365 Jan 7, 2023
Slack notification for Laravel as it should be. Easy, fast, simple and highly testable.

Based on illuminate/mail About Laravel Slack Slack notification for Laravel as it should be. Easy, fast, simple and highly testable. Since it uses On-

Guilherme Pressutto 284 Aug 24, 2022
Lark Notification Channel for laravel.

Lark notifications channel for Laravel This package makes it easy to send Lark using the Laravel notification system. Supports 5.5+, 6.x, 7.x and 8.x.

null 1 Nov 3, 2021
AmaranJS stylish notification for your laravel application.

AmaranJS Laravel 5 Package AmaranJS L5 package is a Laravel wrapper for my jquery plugin AmaranJS.You can create easy and stylish notifications with A

Hakan ERSU 24 Oct 3, 2019
Our Laravel Sendgrid Notification package

laravel-sendgrid-notification-channel Laravel Sendgrid Notification channel Installation To get started, you need to require this package: composer re

Konstruktiv B.V. 4 Feb 3, 2022
Lara-Izitoast : Laravel Notification Package

Lara-Izitoast : Laravel Notification Package This is a laravel notification wrapper build with http://izitoast.marcelodolce.com javascript library. Ho

Apps:Lab KE 34 Nov 19, 2022
Notification package for Laravel

Package is looking for maintainers Please contact me if interested. Notification package for Laravel4 / Laravel5 A simple notification management pack

Edvinas Kručas 531 Oct 12, 2022
An SMS notification channel for the PHP framework Laravel.

Laravel SMS notification channel An SMS notification channel for the PHP framework Laravel. Supported SMS gateways: 46elks Cellsynt Telenor SMS Pro Tw

Andreas 2 Jan 22, 2022
Laravel FCM (Firebase Cloud Messaging) Notification Channel

Laravel FCM Notification Laravel FCM (Firebase Cloud Messaging) Notification Channel Use this package to send push notifications via Laravel to Fireba

Vishal Dudhatra 3 Jul 3, 2022
Livewire Package to display Toast Notification based on TALL Stack.

livewire-toast Livewire Package to display Toast Notification based on TALL Stack. Requirements Make sure that Livewire is installed properly on your

AscSoftwares 35 Nov 12, 2022
ApnsPHP: Apple Push Notification & Feedback Provider

ApnsPHP: Apple Push Notification & Feedback Provider A full set of open source PHP classes to interact with the Apple Push Notification service for th

Immobiliare Labs 1.4k Nov 16, 2022
A filterable git commit summary notification mailer

Git commit notification A symfony application to allow receiving commit notification for all commits in a certain time period. Features: Receive one m

123inkt 4 Jan 3, 2023
Bootstrap 4 & 5 replacement for jGrowl notification

XoopsGrowl module for XOOPS CMS 2.5.11+ XoopsGrowl is a module for XOOPS CMS to configure an alternative to the jGrowl notification using Bootstrap Al

null 1 Oct 28, 2021
Bootstrap 4 & 5 replacement for jGrowl notification

XoopsGrowl module for XOOPS CMS 2.5.11+ XoopsGrowl is a module for XOOPS CMS to configure an alternative to the jGrowl notification using Bootstrap Al

null 1 Oct 24, 2021
WordPress Notification plugin

Notification This is the public repository for Notification - the WordPress plugin. This plugin allow you to send custom notifications about various e

BracketSpace 157 Nov 28, 2022
Bugsnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.

The Bugsnag Notifier for Laravel gives you instant notification of errors and exceptions in your Laravel PHP applications. We support both Laravel and Lumen. Learn more about Laravel error reporting from Bugsnag.

Bugsnag 816 Dec 15, 2022