toporia/audit 问题修复 & 功能扩展

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

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

toporia/audit

Composer 安装命令:

composer require toporia/audit

包简介

Audit logging for Toporia Framework

README 文档

README

Audit logging for Toporia Framework.

Installation

composer require toporia/audit

Auto-Discovery

This package uses Toporia's Package Auto-Discovery system. After installation:

  • Service Provider is automatically registered - no manual registration required
  • Configuration is automatically discovered from extra.toporia.config in composer.json
  • Migrations are automatically included when running php console migrate

To rebuild the package manifest manually:

php console package:discover

Setup

1. Run Migrations

php console migrate

Package migrations are automatically discovered and included. To skip package migrations:

php console migrate --no-packages

2. Publish Config (optional)

php console vendor:publish --provider="Toporia\Audit\AuditServiceProvider"
# Or with tag
php console vendor:publish --tag=audit-config

Usage

1. Add Auditable to Models

use Toporia\Audit\Concerns\Auditable;

class Order extends Model
{
    use Auditable;

    // Optional: specify fields to audit
    protected static array $auditInclude = ['status', 'total'];

    // Optional: exclude sensitive fields
    protected static array $auditExclude = ['internal_notes'];
}

2. Use Middleware (captures user context)

// routes/api.php
$router->group(['middleware' => ['audit']], function ($router) {
    $router->resource('orders', OrderController::class);
});

3. Query Audit History

$history = audit()->getHistory(Order::class, $orderId);

foreach ($history as $entry) {
    echo "{$entry->userName} {$entry->event} at {$entry->timestamp}\n";
    echo "Old: " . json_encode($entry->oldValues) . "\n";
    echo "New: " . json_encode($entry->newValues) . "\n";
}

4. Helper Functions

audit();                                    // Get AuditManager
audit_record($model, 'exported', $meta);    // Custom audit entry
without_auditing(fn() => ...);              // Disable audit temporarily

Configuration

// config/audit.php
return [
    'enabled' => true,
    'default' => 'database', // or 'file'

    'drivers' => [
        'database' => [
            'table' => 'audit_logs',
            'batch_size' => 1000,
        ],
        'file' => [
            'path' => storage_path('logs/audit'),
        ],
    ],

    'exclude' => ['password', 'remember_token'],

    'events' => [
        'created' => true,
        'updated' => true,
        'deleted' => true,
    ],
];

License

MIT

toporia/audit 适用场景与选型建议

toporia/audit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 toporia/audit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 toporia/audit 我们能提供哪些服务?
定制开发 / 二次开发

基于 toporia/audit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-14