https://github.com/unisharp/laravel-audit-trail
https://github.com/unisharp/laravel-audit-trail
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/unisharp/laravel-audit-trail
- Owner: UniSharp
- License: mit
- Created: 2015-11-02T08:56:14.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-03-26T08:12:41.000Z (over 8 years ago)
- Last Synced: 2025-04-05T18:12:30.567Z (about 1 year ago)
- Language: PHP
- Size: 16.6 KB
- Stars: 4
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Laravel Audit Trail
===================
### 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
1. In `/config/app.php`, add the following to `providers`:
```
Unisharp\AuditTrail\AuditServiceProvider::class,
```
and the following to `aliases`:
```
'Audit' => Unisharp\AuditTrail\Facades\Audit::class,
```
2. Run `php artisan vendor:publish`.
3. 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.
```php
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
```php
$User->log($action, $comment = null, $subject = null, $subject_id = null)
```
```php
Audit::log($action, $comment = null)
```
```php
$User->log('log in', 'the action is approved')
```
```php
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` and `subject_id` parameters.
* Other usages
* You can get your model logs by:
```php
$User->getLogs();
```
* Get all the logs by single user by using:
```php
Audit::getByUserId($user_id)
```
* As time grows, logs would be outdated. You may clean them by:
```php
$User->cleanLogs()
```
## License
This package is licensed under [MIT license](https://unisharp.mit-license.org/).