ensi/laravel-auditing
Composer 安装命令:
composer require ensi/laravel-auditing
包简介
laravel auditing
README 文档
README
Opiniated fork of owen-it/laravel-auditing
Installation
You can install the package via composer:
composer require ensi/laravel-auditing
Publish the migrations with:
php artisan vendor:publish --provider="Ensi\LaravelAuditing\LaravelAuditingServiceProvider"
Migrate from 0.2.x to 0.3.0
- Publish new migration
php artisan vendor:publish --provider="Ensi\LaravelAuditing\LaravelAuditingServiceProvider" --tag=migrations-0.3 - If the config
laravel-auditing.phpis published, then replace theresolver.uservalue withEnsi\LaravelAuditing\Resolvers\UserResolver::class
Version Compatibility
| Laravel Auditing | Laravel | PHP |
|---|---|---|
| ^0.1.2 | ^7.x || ^8.x | ^8.0 |
| ^0.2.0 | ^7.x || ^8.x | ^8.0 |
| ^0.3.0 | ^7.x || ^8.x | ^8.0 |
| ^0.3.1 | ^8.x || ^9.x | ^8.0 |
| ^0.3.5 | ^8.x || ^9.x || ^10.x || ^11.x | ^8.0 |
| ^0.4.0 | ^9.x || ^10.x || ^11.x | ^8.1 |
Basic Usage
By default, no modification history is saved for models.
To enable logging for a specific model, you need to add the Support s Audit trait and the Auditable interface to it
use Ensi\LaravelAuditing\Contracts\Auditable; use Ensi\LaravelAuditing\SupportsAudit; class Something extends Model implements Auditable { use SupportsAudit; }
If we change the data of the child models from a logical point of view and want this change to take place under the parent model in the history, it is necessary to set the root entity (i.e. the model) in the transaction before changing the data.
This is done through the Transaction facade or the manager \\Ensi\\LaravelAuditing\\Transactions\\ExtendedTransactionManager
DB::transaction(function () { Transaction::setRootEntity($rootModel); $relatedModel->save(); });
To add data to the history about who made the changes (a specific user, or, for example, a console command), again, you need to do this before changing the data, but through the Subject facade or the injection of \\Ensi\\LaravelAuditing\\Resolvers\\SubjectManager
Subject::attach($subject); // $subject - an object implementing Ensi\LaravelAuditing\Contracts
The subject does not unbind after the transaction is completed.
It can be unlinked manually by calling the Subject::detach() method.
When processing http requests, you can set the subject in middleware. In console commands and handlers, event queues are reassigned during execution.
The subject can be any entity that supports the interface \Ensi\LaravelAuditing\Contracts\Principal.
If the subject is an ongoing task, for example, importing from a file, then it can return the ID of the user who created the task in the getUserIdentifier() method, and return the name of the imported file as the name.
In the user model, the getAuthIdentifier() and getUserIdentifier() methods return the same identifier.
Also, unlike the original package, not only the changed fields are saved in the history, but also the complete state of the model object at the time of the change.
Contributing
Please see CONTRIBUTING for details.
Testing
- composer install
- composer test
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.
ensi/laravel-auditing 适用场景与选型建议
ensi/laravel-auditing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34.16k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ensi/laravel-auditing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ensi/laravel-auditing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 34.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-05