Package Data | |
---|---|
Maintainer Username: | bluora |
Maintainer Contact: | rocco@hnh.digital (Rocco Howard) |
Package Create Date: | 2016-03-06 |
Package Last Update: | 2018-05-30 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 15:03:36 |
Package Statistics | |
---|---|
Total Downloads: | 288 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 8 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 1 |
This package provides a number of traits to track changes made to a model.
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:
'providers' => [
...
Bluora\LaravelModelChangeTracking\ServiceProvider::class,
...
];
Track state changes on your model and by which user for the following states - created
, updated
, deleted
, and restored
.
Adds a saving
event to the model to track changes to all attribute values.
Adds events to set a attribute to the current user for when a model is created
, updated
, archived
, or deleted
.
Add a created_by
, updated_by
, archived_by
, and deleted_by
attributes to your model's database table.
namespace App\Models;
use Bluora\LaravelModelChangeTracking\ChangeByUserTrait;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use ChangeByUserTrait;
}
You can turn off by returning false.
public function getCreatedByColumn()
{
return false;
}
public function getUpdatedByColumn()
{
return false;
}
public function getArchivedByColumn()
{
return false;
}
public function getDeletedByColumn()
{
return false;
}
You can specify the attribute name in the return value.
public function getCreatedByColumn()
{
return 'created_by';
}
public function getUpdatedByColumn()
{
return 'updated_by';
}
public function getArchivedByColumn()
{
return 'updated_by';
}
public function getDeletedByColumn()
{
return 'deleted_by';
}
Tracks model state changes externally in database table.
namespace App\Models;
use Bluora\LaravelModelChangeTracking\LogStateChangeTrait;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use LogStateChangeTrait;
}
Tracks attribute value changes.
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',
];
}