Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hnhdigital-os/laravel-model-change-tracking
Change tracking for models in Laravel. State tracking, attribute logging. User tracking.
https://github.com/hnhdigital-os/laravel-model-change-tracking
Last synced: about 7 hours ago
JSON representation
Change tracking for models in Laravel. State tracking, attribute logging. User tracking.
- Host: GitHub
- URL: https://github.com/hnhdigital-os/laravel-model-change-tracking
- Owner: hnhdigital-os
- License: mit
- Created: 2016-03-06T11:48:40.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-30T04:48:54.000Z (over 6 years ago)
- Last Synced: 2024-12-15T23:36:10.929Z (about 1 month ago)
- Language: PHP
- Homepage:
- Size: 40 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Change tracking for Laravel Eloquent model's
This package provides a number of traits to track changes made to a model.
[![Latest Stable Version](https://poser.pugx.org/hnhdigital-os/laravel-model-change-tracking/v/stable.svg)](https://packagist.org/packages/hnhdigital-os/laravel-model-change-tracking) [![Total Downloads](https://poser.pugx.org/hnhdigital-os/laravel-model-change-tracking/downloads.svg)](https://packagist.org/packages/hnhdigital-os/laravel-model-change-tracking) [![Latest Unstable Version](https://poser.pugx.org/hnhdigital-os/laravel-model-change-tracking/v/unstable.svg)](https://packagist.org/packages/hnhdigital-os/laravel-model-change-tracking) [![License](https://poser.pugx.org/hnhdigital-os/laravel-model-change-tracking/license.svg)](https://packagist.org/packages/hnhdigital-os/laravel-model-change-tracking)
[![Build Status](https://travis-ci.org/hnhdigital-os/laravel-model-change-tracking.svg?branch=master)](https://travis-ci.org/hnhdigital-os/laravel-model-change-tracking) [![StyleCI](https://styleci.io/repos/53252133/shield?branch=master)](https://styleci.io/repos/53252133) [![Test Coverage](https://codeclimate.com/github/hnhdigital-os/laravel-model-change-tracking/badges/coverage.svg)](https://codeclimate.com/github/hnhdigital-os/laravel-model-change-tracking/coverage) [![Issue Count](https://codeclimate.com/github/hnhdigital-os/laravel-model-change-tracking/badges/issue_count.svg)](https://codeclimate.com/github/hnhdigital-os/laravel-model-change-tracking) [![Code Climate](https://codeclimate.com/github/hnhdigital-os/laravel-model-change-tracking/badges/gpa.svg)](https://codeclimate.com/github/hnhdigital-os/laravel-model-change-tracking)
## Install
Via composer:
`$ composer require hnhdigital-os/laravel-model-change-tracking ~1.0`
This package's service provider will autoload from Laravel 5.5.
To enable the service provider in versions prior to Laravel 5.4, edit the config/app.php:
```php
'providers' => [
...
Bluora\LaravelModelChangeTracking\ServiceProvider::class,
...
];
```## State Change
Track state changes on your model and by which user for the following states - `created`, `updated`, `deleted`, and `restored`.## Attribute Change Trait
Adds a `saving` event to the model to track changes to all attribute values.## Change by User Trait
Adds events to set a attribute to the current user for when a model is `created`, `updated`, `archived`, or `deleted`.## Usage
### User tracking of changes.
Add a `created_by`, `updated_by`, `archived_by`, and `deleted_by` attributes to your model's database table.
```php
namespace App\Models;
use Bluora\LaravelModelChangeTracking\ChangeByUserTrait;
use Illuminate\Database\Eloquent\Model;class User extends Model
{
use ChangeByUserTrait;
}
```#### Turn off tracking attribute
You can turn off by returning false.
```php
public function getCreatedByColumn()
{
return false;
}public function getUpdatedByColumn()
{
return false;
}public function getArchivedByColumn()
{
return false;
}public function getDeletedByColumn()
{
return false;
}
```#### Different attribute name
You can specify the attribute name in the return value.
```php
public function getCreatedByColumn()
{
return 'created_by';
}public function getUpdatedByColumn()
{
return 'updated_by';
}public function getArchivedByColumn()
{
return 'updated_by';
}public function getDeletedByColumn()
{
return 'deleted_by';
}
```### Track state changes of models
Tracks model state changes externally in database table.
```php
namespace App\Models;
use Bluora\LaravelModelChangeTracking\LogStateChangeTrait;
use Illuminate\Database\Eloquent\Model;class User extends Model
{
use LogStateChangeTrait;
}
```### Log each attribute value change
Tracks attribute value changes.
```php
namespace App\Models;
use Bluora\LaravelModelChangeTracking\LogChangeTrait;
use Illuminate\Database\Eloquent\Model;class User extends Model
{
use LogChangeTrait;protected $do_not_log = [
'password',
'remember_token',
];
}
```