andreshg112 / laravel-auditing-notifications
A notifications driver for the owen-it/laravel-auditing package. Allows sending notifications with audit data through custom channels.
Requires
- php: ^7.2
- andreshg112/aws-sns: 1.0.2
- illuminate/support: 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.* || 7.*
- owen-it/laravel-auditing: ^9.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.26.1
- mockery/mockery: ^1.2
- orchestra/testbench: ^3.5
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-09-25 04:25:17 UTC
README
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.