unisharp / laravel-audit-trail
Keep a change history for your models using laravel version 5.1.*
Installs: 1 275
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 8
Forks: 1
Open Issues: 0
Type:package
Requires
- php: >=5.5.0
- illuminate/support: ~5.0|~5.1|~5.2|~5.3|~5.4|~5.5
This package is auto-updated.
Last update: 2024-11-15 15:04:52 UTC
README
What is this package for?
- This package is for laravel 5.0/5.1, which helps you create your auditing logs into your database.
Setup
-
In
/config/app.php
, add the following toproviders
:Unisharp\AuditTrail\AuditServiceProvider::class,
and the following to
aliases
:'Audit' => Unisharp\AuditTrail\Facades\Audit::class,
-
Run
php artisan vendor:publish
. -
Run
php artisan migrate
.
Usage
All your logs will be recorded in 'audit_trails' table.
-
You need to add a trait to the model you're going to audit.
class User extends Eloquent { use \Unisharp\AuditTrail\Auditable; protected $table = 'users'; protected $hidden = ['password']; protected $fillable = ['username', 'email', 'password']; }
-
In any place you want to audit your user logs
$User->log($action, $comment = null, $subject = null, $subject_id = null)
Audit::log($action, $comment = null)
$User->log('log in', 'the action is approved')
Audit::log('log in', 'the action is approved')
- $User is an Eloquent Object here.
- The second, third parameters are optional.
- You could put your modified column and column id to
subject
andsubject_id
parameters.
-
Other usages
-
You can get your model logs by:
$User->getLogs();
-
Get all the logs by single user by using:
Audit::getByUserId($user_id)
-
As time grows, logs would be outdated. You may clean them by:
$User->cleanLogs()
-
License
This package is licensed under MIT license.