Projectslaravel-audit-logsActivity Logs

Laravel Audit Logs

Package

Audit logging for Eloquent models and auth events in Laravel.

Activity Logs

Attach automatic activity logging to any Eloquent model with the contract and trait:

use BradieTilley\AuditLogs\Concerns\HasAuditLogs;
use BradieTilley\AuditLogs\Contracts\WithAuditLogs;
use Illuminate\Database\Eloquent\Model;

class Product extends Model implements WithAuditLogs
{
    use HasAuditLogs;
}

The trait registers HasAuditLogsObserver (configurable via audit-logs.classes.observer) after the model has booted.

Events recorded

Eloquent eventExample action
createdProduct created
updatedProduct updated (with change details — see Change Logging)
deletedProduct deleted (soft or hard delete)
forceDeletedProduct force deleted
restoredProduct restored

On SoftDeletes models, a force-delete records only the forceDeleted action (the intermediate deleted observer call is skipped).

Display names

Human-readable model and field labels can be overridden:

use BradieTilley\AuditLogs\AuditLogUtil;

AuditLogUtil::usingModelNames([
    Product::class => 'Catalogue product',
]);

AuditLogUtil::usingFieldNames([
    'sku' => 'SKU',
]);

Subclassing models

If a child model extends a parent that already uses HasAuditLogs, do not re-apply the trait on the child — that would register the observer twice.

Next steps