This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.
You can install the package via composer:
composer require metko/activiko
Just use the trait RecordActiviko in the model you want to be recorded.
use Metko\Activiko\Traits\RecordActiviko;
The model will record automatically the following events : created
, update
and deleted
.
If you want to modify this globally, you can update the recordableEvents
key in the config file. Or at the top of your model, just declare a property call recordable events:
protected static $recordableEvents = ['updated']; // Only updated event will be recorded.
Optionally, you can specify the event to be recorded before to execute an action.
public function createArtBoard($artist)
{
app('activiko')->onlyRecordsEvents(['updated']);
$artist->create(['awesomeness' => 'yey']);
$artist->update(['awesomeness' => 'much more']);
//Only the updated event will trigger the record activity
}
You can also filter fields to not be recorded in the changes property like this:
protected static $excludeOfRecords = ['body']; // Only updated event will be recorded.
By default, it will exclude the fields
id
,created_at
andupdated_at
. You can override this this in the config file.
protected static $fieldsToRecords = ['name', 'size', 'color']; // Only record this fields
You can also specify the fields to be register with the model before to execute an action like so:
$artist->disableFields(['body']); // Fields body will not be in the changes property
You can disable a record for a specific model like so:
app('activiko')->disable();
app('activiko')->enable();
// Or
$artist->disableRecord();
$artist->enableRecord();
You can call the method getChanges on activity model or call directly the lastChanges from the model recorded
$artist->lastChanges(); // Return array
// [
// 'before' => [`
// 'name' => "title",
// 'body' => 'body'
// ],
// 'after' => [`
// 'name' => "New title",
// 'body' => 'New body'
// ]
// ]
$artist->lastChanges('name');
// [
// 'before' => "title"
// 'after' => 'New title'
// ]
$artist->lastChanges('name', 'before');
// "title"
$artist->lastChanges("before"); // Return array
// [
// 'before' => [`
// 'name' => "title",
// 'body' => 'body'
// ],
// ]
$artist->lastChanges("after"); // Return array
// [
// 'after' => [`
// 'name' => "New title",
// 'body' => 'New body'
// ],
// ]
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email thomas.moiluiavon@gmail.com instead of using the issue tracker.
- Thomas Moiluiavon
- All Contributors
The MIT License (MIT). Please see License File for more information.