iqbalatma/laravel-audit
Composer 安装命令:
composer require iqbalatma/laravel-audit
包简介
Use to auditing data changes
README 文档
README
Laravel Audit is a laravel package that use to track changes on your process. It will also track client ip address, http method, endpoint, user request, user agent, user that making changes, object that changes, before and after data changes. You need to set object to let audit know which model/data that being change. After that, you also need to set before and after data.
How to install ?
Here is how to install the package :
composer require iqbalatma/laravel-audit
How to publish vendor ?
You need to publish vendor (migration and config). Here is how to publish vendor :
php artisan vendor:publish --provider="Iqbalatma\LaravelAudit\Providers\LaravelAuditServiceProvider"
After publishing migration, you can run the migration.
php artisan migrate
How to use ?
First you need to initiate the audit service. After that, you can set all data with available method.
<?php use Iqbalatma\LaravelAudit\AuditService; use App\Models\Product; use Illuminate\Support\Facades\Auth; $product = Product::create([ "name" => "laptop", "category" => "digital", "price" => 10000000 ]); $audit = AuditService::init(); #initiate object #or $audit = AuditService::init(action: "CREATE_PRODUCT", message: "Create product via method abc in class xyz", entryObject: $product, guard: "web", user: Auth::user()); #all of this value is optional AuditService::init("CREATE_PRODUCT", "Create product via method abc in class xyz") ->setEntryObject($product) #required, and become optional if you already set via init ->addSingleTrail($role, null, $role->toArray()) #required ->setAppName("E-Commerce") #optional ->setTag(["level" => "important"]) #optional ->setAdditional(["role" => "ADMIN"]) #optional ->setActor(Auth::user()) #optional ->execute(); #example for data relational attach/detach $role->fill($requestedData)->save(); $audit = \Iqbalatma\LaravelAudit\AuditService::init(AuditAction::UPDATE_ROLE, __METHOD__, $role) ->addSingleTrail($role, $roleBefore, $role->toArray()); $permissionBefore = $role->permissions ->map(fn($p) => $p->only(['id', 'name'])) ->toArray(); $role->permissions()->sync($requestedData['permissions'] ?? []); $role->load('permissions'); $permissionAfter = $role->permissions ->map(fn($p) => $p->only(['id', 'name'])) ->toArray(); $audit->addRelationalTrail(Table::PERMISSIONS->value, $permissionBefore, $permissionAfter); $audit->execute(); ?>
iqbalatma/laravel-audit 适用场景与选型建议
iqbalatma/laravel-audit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 519 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 02 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 iqbalatma/laravel-audit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iqbalatma/laravel-audit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 519
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-02-14