rajmundtoth0/laravel-auditing-elasticsearch-driver 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rajmundtoth0/laravel-auditing-elasticsearch-driver

最新稳定版本:1.4.3

Composer 安装命令:

composer require rajmundtoth0/laravel-auditing-elasticsearch-driver

包简介

An Elasticsearch driver for the owen-it/laravel-auditing package.

README 文档

README

Version codecov PHPStan Build Codacy Badge PHP Version Require License Total Downloads

Laravel Auditing Elasticsearch Driver

This is a community elasticsearch driver for Laravel Auditing.

Contents

Requirements

Version
php >= 8.2
Laravel ^11|^12
elasticsearch/elasticsearch ^8.0
owen-it/laravel-auditing ^13.0|^14.0

Installation

composer require rajmundtoth0/laravel-auditing-elasticsearch-driver 

Config

The driver key of the config file should look like so:

 ... 'driver' => rajmundtoth0\AuditDriver\Services\ElasticsearchAuditService::class, ... 

The drivers key of the config file should look like so:

 ... 'drivers' => [ 'database' => [ 'table' => 'audits', 'connection' => null, ], 'elastic' => [ 'hosts' => [ env('AUDIT_HOST', 'https://0.0.0.0:9200') ], 'userName' => env('ELASTIC_AUDIT_USER', 'elastic'), 'password' => env('ELASTIC_AUDIT_PASSWORD', 'a_very_strong_password'), 'useBasicAuth' => env('AUDIT_BASIC_AUTH', true), 'useCaCert' => env('AUDIT_USE_CERT', true), 'certPath' => env('AUDIT_CERT_PATH', false), 'index' => env('AUDIT_INDEX', 'laravel_auditing'), 'type' => env('AUDIT_TYPE', 'audits'), ], 'queue' => [ 'enabled' => env('AUDIT_QUEUE_ENABLED', false), 'connection' => env('AUDIT_QUEUE_CONNECTION', false), 'name' => env('AUDIT_QUEUE_NAME', 'audits'), ], ], ... 

Setup

Run the following artisan command after installation to create the Elasticsearch index:

php artisan es-audit-log:setup

Usage

The following structure ensures to store the audits in Elasticsearch:

<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use OwenIt\Auditing\Auditable; use OwenIt\Auditing\Contracts\Auditable as AuditableContract; class SomeModel extends Model implements AuditableContract { use Auditable; // ... } 

And provides the following ways to retrieve the logs related to the given model:

$someModel->audit_log

$someModel->elasticsearchAuditLog()

Located in the ElasticsearchAuditable trait.

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(); } } 

Queue:

When the queue configuration is set, the driver will dispatch a job to index each document.

Contribution

Pull requests has to be opened against the master branch.

统计信息

  • 总下载量: 55.02k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固