andreshg112/laravel-auditing-notifications

A notifications driver for the owen-it/laravel-auditing package. Allows sending notifications with audit data through custom channels.

1.1.0 2019-04-11 21:37 UTC

README

Latest Version on Packagist Build Status StyleCI Scrutinizer Code Quality Code Coverage Total Downloads

This package allows you to send notifications with audit data instead of saving it to an accessible database. By default, it sends notifications through AWS SNS using the package lab123it/aws-sns.

Use case

If you have some microservices and want to have centralized auditing, this could be helpful.

Requirements

  • PHP >= 7.1
  • Laravel >= 5.2 && < 5.8

Installation

Step 1

This package depends on owen-it/laravel-auditing:^8.0 and lab123it/aws-sns:dev-master, so you have to install and configure them first in order to make this work.

You can install the package via composer:

composer require andreshg112/laravel-auditing-notifications

Step 2

Change the audit default driver:

return [
    // ...
    /*
    |--------------------------------------------------------------------------
    | Audit Driver
    |--------------------------------------------------------------------------
    |
    | The default audit driver used to keep track of changes.
    |
    */

    'driver' => Andreshg112\LaravelAuditingNotifications\NotificationDriver::class,
];

You can make this locally on a model. Please see the documentation: http://laravel-auditing.com/docs/8.0/audit-drivers.

Step 3

In your config/audit.php file, add this:

return [
    // ...

    // andreshg112/laravel-auditing-notifications

    'notification-driver' => [
        // Required if you're going to use different notifications channels for sending audit data.
        'notifications' => [
            Andreshg112\LaravelAuditingNotifications\AuditSns::class,

            // Or this if you want to queue the delivery of the message.
            // https://laravel.com/docs/5.2/queues
            // Andreshg112\LaravelAuditingNotifications\AuditSnsQueue::class,
        ],

        // Required if you're going to use the default Andreshg112\LaravelAuditingNotifications\AuditSns Notification.
        'sns' => [
            'topic_arn' => 'arn:aws:sns:us-east-1:xxxxxxxxxxxx:auditing-notifications',
        ],
    ],
];

Usage

Add the Illuminate\Notifications\Notifiable trait to the models you want to audit, besides Auditable contract and trait.

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Vehicle extends Model implements \OwenIt\Auditing\Contracts\Auditable
{
    use \OwenIt\Auditing\Auditable, Notifiable;
}

That's all! Just execute an auditable event over the model in order to send a notification.

Testing

composer test

Changelog

Please see Releases for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email andreshg112@gmail.com instead of using the issue tracker.

Credits

License

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

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.