Download the PHP package misakstvanu/laravel-model-log without Composer
On this page you can find all versions of the php package misakstvanu/laravel-model-log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download misakstvanu/laravel-model-log
More information about misakstvanu/laravel-model-log
Files in misakstvanu/laravel-model-log
Package laravel-model-log
Short Description A Laravel package for logging model changes
License MIT
Informations about the package laravel-model-log
Laravel Model Log
A Laravel package that automatically logs all changes to Eloquent models for audit trails.
Installation
Install the package via Composer:
Publish the migration and config files:
Run the migration:
Usage
Add the Loggable trait to any model you want to log:
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 changenormalize_datetime_to_db_format: Normalize date/datetime values to DB format before logging (default:false), useful to avoid false-positive changes when equivalent datetime values use different formatsuser_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
Testing
Run the package tests with:
License
This package is open-sourced software licensed under the MIT license.