joshbrw/laravel-audit-logging 问题修复 & 功能扩展

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

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

joshbrw/laravel-audit-logging

Composer 安装命令:

composer require joshbrw/laravel-audit-logging

包简介

Fully translatable Audit Logging in Laravel.

README 文档

README

A simple, easy-to-use audit logging system with translation at the heart. Uses UUIDs for easy dataset merging and management.

Installation

  1. Add Joshbrw\AuditLogging\AuditLoggingServiceProviders, under the providers key in config/app.php.
  2. Add 'Audit' => Joshbrw\AuditLogging\Facades\Audit::class, under the aliases key in config/app.php to register the Facade
  3. Run php artisan vendor:publish --provider="Joshbrw\\AuditLogging\\AuditLoggingServiceProvider" - this will publish the migration(s) to your top-level database/migrations directory.
  4. Run php artisan migrate to run the migration(s) provided with this package.
  5. On each of your Eloquent models that you wish to log, add the Joshbrw\AuditLogging\Traits\Eloquent\Auditable trait.

Usage

Basic Attributes

Every Audit Log item has two required attributes:

  • auditable_type | auditable_id - The entity the audit relates to
  • message_key - The translation key of the message

The option attributes are:

  • message_replacements - An array of replacements that should be passed to the translator when displaying the audit log.
  • data - Any array/object of data that you'd like to store against the Audit Log.
  • user_id - The ID of the User performing the action being logged. Supports Laravel's Auth and Sentinel by default, allows for custom adapters via the UserResolver

Using the Helper Methods & Service

This library ships with an audit() method, with the following syntax:

    /**
     * Helper method for logging an audit entry.
     * @param mixed $entity The entity to create the log for
     * @param string $messageKey The key of the translatable message to use
     * @param array|null $messageReplacements Array of replacements for the message
     * @param array|null $data Any data to attribute to the audit log item
     * @return AuditLog Audit log instance
     */
    function audit($entity, string $messageKey, array $messageReplacements = null, array $data = null): AuditLog {

Which simply proxies through to the Joshbrw\AuditLogging\AuditLogManager service's log() method, which accepts the same parameters.

Facade

The package also ships with a Facade which can be used as \Audit:: and proxies through to the AuditLogManager, such as Audit::log() and Audit::translate().

Fetching Audit Logs

You can use the AuditLogRepository to fetch Audit Logs for a specific Eloquent Model:

  1. Ensure that the entity is using the Auditable trait.
  2. See the following code to learn how to fetch all Audit Logs for the model, in reverse chronological order:
$user = App\User::first();
$auditLogs = app(Joshbrw\AuditLogging\Repositories\AuditLogRepository::class)->getAllAuditLogs($user);

joshbrw/laravel-audit-logging 适用场景与选型建议

joshbrw/laravel-audit-logging 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.41k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-04