godforhire / databasenotifications by godforhire

Database notifications driver for Laravel 5.3 and up
87
1
1
Package Data
Maintainer Username: godforhire
Package Create Date: 2017-02-05
Package Last Update: 2019-09-14
Language: PHP
License: MIT
Last Refreshed: 2025-02-05 03:15:59
Package Statistics
Total Downloads: 87
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 1
Total Forks: 1
Total Open Issues: 0

Database Notification Channel for Laravel 5.3 and up

Latest Version on Packagist Software License Total Downloads

This package makes it easy to send database notifications with Laravel 5.3 and up from third-party packages. Those often allow you to send mail or slack notifications, but with this package you can also send them to the notification table. For others, simply use Laravel's own notifications.

Contents

Installation

You can install the package via composer:

composer require godforhire/databasenotifications

Usage

Now you can use the channel in your via() method inside the notification:

use godforhire\DatabaseNotifications\DatabaseChannel;
use godforhire\DatabaseNotifications\DatabaseMessage;
use Illuminate\Notifications\Notification;

class BackupHasFailed extends Notification
{
    public function via($notifiable)
    {
        return [DatabaseChannel::class];
    }

    public function toDatabase($notifiable)
    {
        return DatabaseMessage::create()
                    ->user(1)
                    ->data([
                        'event' => 'Backup failed',
                    	'description' => 'Daily backup of Your App has failed: reason, disk S3 is unreachable.',
                    	'...' => '...'
                    ]);
    }
}

Available Message methods

  • user The user to send the notification to.
  • data An array with custom fields. This can contain any key value pair you want.

License

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