Download the PHP package patoui/model-history without Composer
On this page you can find all versions of the php package patoui/model-history. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download patoui/model-history
More information about patoui/model-history
Files in patoui/model-history
Package model-history
Short Description A Laravel package to track model changes
License MIT
Homepage https://github.com/patoui/model-history
Informations about the package model-history
๐ Laravel Model History Package
A Laravel package that allows you to track changes to your Eloquent models (history) in an opt-in fashion. The package provides extensibility, so you can store changes in your preferred storage system.
โจ Features
- Opt-in tracking: Models choose to track changes by using a trait
- Tracks creation and updates: Captures both model creation and modification events
- Extensibility: Use the default Eloquent implementation or create your own
- Configurable: Configuration available for additional control
๐ฆ Installation
You can install the package via composer:
Optionally, you can publish the config file with:
Optionally, you can publish and run the migrations with:
You can publish both config and migrations at once with:
โ๏ธ Configuration
After publishing the config file, you can customize the package behavior by editing config/model-history.php
.
๐ฏ Customizing the model history
You can customize which model is used for storing changes:
๐ซ Customizing Excluded Properties
You can customize which properties are excluded from the model history by modifying the exclude_properties
array in your published config file. For example, if you want to also exclude password
fields and any _token
fields:
๐ง Model configuration
You may add an additional property to the model to override the default configuration of excluded properties
๐ Usage
๐ Basic Usage
To start tracking changes for a model, simply add the TrackModelHistory
trait and the TrackModelHistoryContract
interface:
Now any changes to this model will be automatically tracked:
๐๏ธ Using non-Eloquent storage
This package provides a ModelHistoryRepositoryContract
so you may implement your own repository. Once implemented you can simply override the registered singleton in your app service provider
๐ Using ClickHouse
Here's an example using ClickHouse with the Laravel ClickHouse package.
First, install the Laravel ClickHouse package:
Complete the setup from the package.
Create a migration for the changes
table:
Create a ClickHouse model for the model history:
Now publish the config
Now update the model
with your own
๐งช Testing
๐ Changelog
Please see CHANGELOG for more information on what has changed recently.
๐ฅ Credits
- Patrique Ouimet
- All Contributors
๐ License
The MIT License (MIT). Please see License File for more information.
All versions of model-history with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0