|
| 1 | +This driver provides the ability to save your model audits in elasticsearch. |
| 2 | + |
| 3 | +### Installation |
| 4 | + |
| 5 | +This driver requires that you are using `owen-it/laravel-auditing: ^6.0`. Provided this is fulfilled, |
| 6 | +you can install the driver like so: |
| 7 | + |
| 8 | +``` |
| 9 | +composer require iconscout/laravel-auditing-elasticsearch |
| 10 | +``` |
| 11 | + |
| 12 | +### Setup |
| 13 | + |
| 14 | +You need to add the following config entries in config/audit.php if you need to change the default behaviour of the driver. |
| 15 | +The `queue` key of the config file should look like so: |
| 16 | + |
| 17 | +``` |
| 18 | + ... |
| 19 | + 'queue' => env('AUDIT_QUEUE', true), |
| 20 | + ... |
| 21 | +``` |
| 22 | + |
| 23 | +OR |
| 24 | + |
| 25 | +``` |
| 26 | + ... |
| 27 | + 'queue' => env('AUDIT_QUEUE', [ |
| 28 | + 'queue' => 'default', |
| 29 | + 'connection' => 'redis' |
| 30 | + ]), |
| 31 | + ... |
| 32 | +``` |
| 33 | + |
| 34 | +The `driver` key of the config file should look like so: |
| 35 | + |
| 36 | +``` |
| 37 | + ... |
| 38 | + 'driver' => Iconscout\Auditing\Drivers\ElasticSearch::class, |
| 39 | + ... |
| 40 | +``` |
| 41 | + |
| 42 | +The `drivers` key of the config file should look like so: |
| 43 | + |
| 44 | +``` |
| 45 | + ... |
| 46 | + 'drivers' => [ |
| 47 | + 'database' => [ |
| 48 | + 'table' => 'audits', |
| 49 | + 'connection' => null, |
| 50 | + ], |
| 51 | + 'es' => [ |
| 52 | + 'client' => [ |
| 53 | + 'hosts' => [ |
| 54 | + env('AUDIT_HOST', 'localhost:9200') |
| 55 | + ] |
| 56 | + ], |
| 57 | + 'index' => env('AUDIT_INDEX', 'laravel_auditing'), |
| 58 | + 'type' => env('AUDIT_TYPE', 'audits') |
| 59 | + ], |
| 60 | + ], |
| 61 | + ... |
| 62 | +``` |
| 63 | + |
| 64 | +### Usage |
| 65 | + |
| 66 | +You can use the driver in any Auditable model like so: |
| 67 | + |
| 68 | +``` |
| 69 | +<?php |
| 70 | +namespace App\Models; |
| 71 | +
|
| 72 | +use Iconscout\Auditing\Drivers\ElasticSearch; |
| 73 | +use Illuminate\Database\Eloquent\Model; |
| 74 | +use OwenIt\Auditing\Auditable; |
| 75 | +use OwenIt\Auditing\Contracts\Auditable as AuditableContract; |
| 76 | +
|
| 77 | +class SomeModel extends Model implements AuditableContract |
| 78 | +{ |
| 79 | + use Auditable; |
| 80 | +
|
| 81 | + /** |
| 82 | + * ElasticSearch Audit Driver |
| 83 | + * |
| 84 | + * @var Iconscout\Auditing\Drivers\ElasticSearch |
| 85 | + */ |
| 86 | + protected $auditDriver = ElasticSearch::class; |
| 87 | +
|
| 88 | + // ... |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +More information on using customer drivers with owen-it/laravel-auditing can be found on their [homepage](http://laravel-auditing.com/docs/6.0/audit-drivers) |
0 commit comments