Hosmel Quintana
Laravel Audit Logs
Introduction
Installation
Configuration
Basic usage
Recording Audit Logs
Actors and Targets
Querying Audit Logs
Testing Audit Logs
Advanced usage
Batching and Correlating Logs
Customizing the Audit Log Model
View on GitHub

Customizing the Audit Log Model

Add application-specific scopes, relationships, or casts to stored logs.

Create a custom model when your application needs reusable query scopes, relationships, or additional casts.

Extend the package model

The custom model must extend HosmelQ\AuditLog\Models\AuditLog:

php
namespace App\Models;

use HosmelQ\AuditLog\Models\AuditLog as BaseAuditLog;

class AuditLog extends BaseAuditLog
{
}

The base model already provides the configured connection and table, casts structured values, disables timestamps, and supports mass pruning.

Register the model

Register the class once while your application boots:

php
namespace App\Providers;

use App\Models\AuditLog;
use HosmelQ\AuditLog\DatabaseAuditLogManager;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        DatabaseAuditLogManager::useModel(AuditLog::class);
    }
}

The registered model is used when audit logs are written. Query the same class when consuming your application-specific scopes or relationships.

Batching and Correlating Logs