misakstvanu/laravel-model-log
最新稳定版本:v1.0.4
Composer 安装命令:
composer require misakstvanu/laravel-model-log
包简介
A Laravel package for logging model changes
README 文档
README
A Laravel package that automatically logs all changes to Eloquent models for audit trails.
Installation
Install the package via Composer:
composer require misakstvanu/laravel-model-log
Publish the migration and config files:
php artisan vendor:publish --provider="Misakstvanu\ModelLog\ModelLogServiceProvider" --tag=model-log-migrations php artisan vendor:publish --provider="Misakstvanu\ModelLog\ModelLogServiceProvider" --tag=model-log-config
Run the migration:
php artisan migrate
Usage
Add the Loggable trait to any model you want to log:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Misakstvanu\ModelLog\Traits\Loggable; class User extends Model { use Loggable; // ... }
That's it! All changes to the model will be automatically logged to the model_logs table.
Logged Operations
The package logs the following operations:
create: When a new record is createdupdate: When an existing record is updateddelete: When a record is soft deleted (if the model uses soft deletes)soft_delete: When a record is soft deletedrestore: When a soft deleted record is restoredforce_delete: When a record is permanently deleted
Configuration
You can customize the behavior by editing config/model-log.php:
models.include: Array of models to log (if empty, all models with the trait are logged)models.exclude: Array of models to exclude from loggingexcluded_attributes: Attributes to exclude from logging (e.g., passwords)track_users: Whether to track the user who made the changeuser_model: Custom user model class
Database Schema
The model_logs table contains:
model_class: The class name of the modelmodel_id: The primary key of the modeloperation: The type of operationold_values: JSON of the old attribute values (for updates/deletes)new_values: JSON of the new attribute values (for creates/updates)user_id: The ID of the user who made the change (nullable)created_at: Timestamp of the change
License
This package is open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 54
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-27