Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Laravel Auditable

yajra/laravel-auditable image

Laravel Auditable stats

Downloads
108.6K
Stars
134
Open Issues
0
Forks
24

View on GitHub →

A simple Laravel user auditing package for Eloquent Model.

Laravel Auditable

Laravel Auditable is a simple Laravel auditing package for your Eloquent Model. This package automatically inserts/updates an audit log on your table on who created and last updated the record.

Install via Composer

composer require yajra/laravel-auditable

Publish config file

If you want to modify the withDefault option on auditable columns, you may publish the config file.

php artisan vendor:publish --tag=auditable

Usage

Update your model's migration and add created_by and updated_by field using the auditable() blueprint macro.

Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 100);
$table->auditable();
$table->timestamps();
});

Then use AuditableTrait on your model.

namespace App;
 
use Yajra\Auditable\AuditableTrait;
 
class User extends Model
{
use AuditableTrait;
}

Soft Deletes

If you wish to use Laravel's soft deletes, use the auditableWithDeletes() method on your migration instead:

Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 100);
$table->auditableWithDeletes();
$table->timestamps();
$table->softDeletes()
});

Afterwards, you need to use AuditableWithDeletesTrait on your model.

namespace App;
 
use Yajra\Auditable\AuditableWithDeletesTrait;
 
class User extends Model
{
use AuditableWithDeletesTrait, SoftDeletes;
}

Dropping columns

You can drop auditable columns using dropAuditable() method, or dropAuditableWithDeletes() if using soft deletes.

Schema::create('users', function (Blueprint $table) {
$table->dropAuditable();
});

And you're done! The package will now automatically add a basic audit log for your model to track who inserted and last updated your records.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email aqangeles@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Yajra Laravel Auditable Related Articles

A DynamoDB Driver for the Laravel Auditing Package image

A DynamoDB Driver for the Laravel Auditing Package

Read article
Laravel Audit Log image

Laravel Audit Log

Read article
First Factor One-Time Passwords for Laravel with OTPZ image

First Factor One-Time Passwords for Laravel with OTPZ

Read article
Accessing Raw Model Data with Laravel's attributesToArray Method image

Accessing Raw Model Data with Laravel's attributesToArray Method

Read article
Event sourcing in Laravel with the Verbs package image

Event sourcing in Laravel with the Verbs package

Read article
Track Laravel Model Changes with Laravel Auditing image

Track Laravel Model Changes with Laravel Auditing

Read article
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Tighten logo

Tighten

We help companies turn great ideas into amazing apps, products, and services.

Tighten
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic