PHP code example of rajmundtoth0 / laravel-auditing-elasticsearch-driver
1. Go to this page and download the library: Download rajmundtoth0/laravel-auditing-elasticsearch-driver library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rajmundtoth0 / laravel-auditing-elasticsearch-driver example snippets
trait ElasticSearchAuditable
{
/**
* @return Collection<int, mixed>
*/
public function elasticsearchAuditLog(int $page = 1, int $pageSize = 10, string $sort = 'desc'): Collection
{
/** @var ElasticsearchAuditService */
$elasticsearchAuditService = resolve(ElasticsearchAuditService::class);
$result = $elasticsearchAuditService->searchAuditDocument(
model: $this,
pageSize: $pageSize,
from: --$page * $pageSize,
sort: $sort,
);
return collect($result->asArray());
}
/**
* @return Collection<int, mixed>
*/
public function getAuditLogAttribute(): Collection
{
return $this->elasticsearchAuditLog();
}
}