carlosdev/model-change-logger
最新稳定版本:v1.0.3
Composer 安装命令:
composer require carlosdev/model-change-logger
包简介
Laravel package to log changes (update and delete) in Eloquent models, including changed fields, user, and timestamps.
关键字:
README 文档
README
Laravel library for recording changes (update and delete) in models.
Records modified fields, their previous value, new value, the responsible user, and the date of the change in a database table.
📦 Installation
Add the package to your project via Composer:
composer require carlosdev/model-change-logger
Make sure you have PHP 8.0+ and Laravel 10.
🔧 Configuration
Publish and run migrations:
php artisan migrate
Use the trait in the model you want to audit:
use CarlosDev\ModelChangeLogger\Traits\TracksChanges; class JobOffer extends Model { use TracksChanges; }
(Optional) Audit only specific fields: If you want to record only certain fields, define the $auditFields property in your model:
protected array $auditFields = ['job_offer_status_id', 'title'];
🧠 What does it record?
- Changes to individual fields when performing update().
- Deletions (delete and forceDelete), saving the event but without specific fields.
- Responsible user (Auth::id()).
- Affected model and ID.
- Date and time of the change.
📄 Structure of the model_changes table
| Field | Description |
|---|---|
| model_type | Class of the affected model (App\Models\X) |
| model_id | ID of the modified model |
| field | Field that changed |
| old_value | Previous value of the field |
| new_value | New value of the field |
| user_id | ID of the user who made the change |
| event | Type of event (updated, deleted, etc.) |
| changed_at | Date and time of the change |
✅ Compatibility
- PHP: >= 8.0
- Laravel: ^10.0
📬 Contributions
Suggestions, improvements, and pull requests are welcome! 🚀
This package is designed for projects that require change traceability without depending on complex auditing packages.
📄 License
MIT © CarlosDev
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-23