This package makes it easy to send database notifications with Laravel 6 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.
You can install the package via composer:
composer require godforhire/databasenotifications
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.',
'...' => '...'
]);
}
}
user
The user to send the notification to.data
An array with custom fields. This can contain any key value pair you want.
The MIT License (MIT). Please see License File for more information.