tochka-developers / model-history
Simple history for Laravel models
Installs: 2 374
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 0
Type:package
Requires
- php: ^7.4|8.0.*|8.1.*|8.2.*
- ext-json: *
- ext-pdo: *
- illuminate/database: ^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0
- illuminate/support: ^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0
This package is auto-updated.
Last update: 2024-10-30 01:59:21 UTC
README
Easily add keeping track of model modifications.
Installation
-
Add
"tochka-developers/model-history":"^0.1"
to therequire
section of yourcomposer.json
-
Publish package assets:
php artisan vendor:publish
-
You may now edit the config file
model-history.php
to specify the name of the table to store history records. Please do it before running the migrations. Default name ishistory
which is quite reasonable. -
Use
\Tochka\ModelHistory\HasHistory
trait in your model.
History structure
History records for all tracked models are stored in the same table
specified in the config file (history
is the default name).
Each record contains the following data:
changed_at
- time of modification;entity_name
- name of the table containing tracked model records;entity_id
- ID of the row in the tracked table the history entry relates to;action
- type of modification. The possible values arecreate
,update
,delete
andrestore
.new_data
- a JSON containing new values. Therefore each history record is essentially a diff to the previous version of the model.
Warning
The history table always grows and is NEVER CLEANED UP by this package. Please consider the possibility of the history table becoming the largest in your database and occupying more space than all other tables ultimately exhausting all available disk space.