Download the PHP package insenseanalytics/laravel-user-audit-trails without Composer
On this page you can find all versions of the php package insenseanalytics/laravel-user-audit-trails. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download insenseanalytics/laravel-user-audit-trails
More information about insenseanalytics/laravel-user-audit-trails
Files in insenseanalytics/laravel-user-audit-trails
Package laravel-user-audit-trails
Short Description User audit trails for Laravel Eloquent.
License MIT
Informations about the package laravel-user-audit-trails
Laravel User Audit Trails
This package is created to add audit user trails by using Laravel Eloquent ORM. Using this package, you would be able to record in the respective database tables, the created_by
, updated_by
and deleted_by
user IDs.
Basic Example
Add the audit trail columns in your database migrations like so:
Next, in your model just use the HasUserTrails
and HasDeleteTrails
trait to automatically setup audit user trails like so:
That's it! Now, sit back and observe the magic of audit user trails. When a new record is created, created_by
will be updated to the user ID that created it. When a record is updated, updated_by
will be updated to the user ID that updated it. When a record is soft deleted, deleted_by
will be updated to the user ID that deleted it.
Requirements
Quick Installation
Service Provider (Optional / auto discovered on Laravel 5.5+)
Register provider on your config/app.php
file.
Setting Up Custom Column Names
If you want to override the default audit trail names of created_by
, updated_by
and deleted_by
, you may do so like so:
In your database migration, add the audit trail columns like so:
Next, in your model, override the static properties CREATED_BY
, UPDATED_BY
and DELETED_BY
. Note that PHP does not allow overriding static properties in the same class, so you would need to extend your model class from a base model class that uses the \Insense\LaravelUserAuditTrails\HasUserTrails
trait like so:
First create your base model class (if not already created). If already created, just add the trait.
Next, override the static properties CREATED_BY
, UPDATED_BY
and DELETED_BY
in your model (that extends the base model) like so:
Omitting Updated By or Created By Columns
If you wish to omit one of the audit trail columns, you can just set the one you would like to omit to null in your database migration like so:
The example above omits the updated_by column. You can also do the reverse to omit updated_by by setting the first argument to null.
Next, override the static properties CREATED_BY
and UPDATED_BY
in your model (that extends the base model) to set the omitted property to null like so:
Contributing
We are open to PRs as long as they're backed by tests and a small description of the feature added / problem solved.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-user-audit-trails with dependencies
illuminate/database Version ^5.5|^6.0|^7.0|^8.0