Audit Trail Docs

ElementAttributeValueAudit extends BaseAudit

Payroll element classification (ElementAttributeValue) audit trail implementations.

Classified elements are global, so entries belong to no company and are dispatched after commit.

Table of Contents

Methods

elementClassificationRemovedLog()  : void
Log a payroll element classification removed
elementClassificationsBackfilledLog()  : void
Log a payroll element classification backfill run
elementClassifiedLog()  : void
Log a payroll element classified
elementReclassifiedLog()  : void
Log a payroll element reclassified
addAuditLog()  : void
Log an audit trail entry
getCompanyId()  : int
Extract company ID from various model types.
getUserId()  : int
Get the current authenticated user ID, or fallback to job context user ID.

Methods

elementClassificationRemovedLog()

Log a payroll element classification removed

public static elementClassificationRemovedLog(mixed $record, string $attributeCode[, int $userId = 0 ]) : void
Parameters
$record : mixed

The removed ElementAttributeValue data, carrying the reason

$attributeCode : string

The attribute's code

$userId : int = 0

The ID of the user who performed the action (optional)

Tags
audit-event

Element Classification Removed

audit-module

PAYROLL

audit-action

DELETE

audit-trigger

When an element's live value for an attribute is removed

elementClassificationsBackfilledLog()

Log a payroll element classification backfill run

public static elementClassificationsBackfilledLog(mixed $summary[, int $userId = 0 ]) : void
Parameters
$summary : mixed

The run's counts; its id is the audit object id

$userId : int = 0

The ID of the user who performed the action (optional, 0 for a system run)

Tags
audit-event

Element Classifications Backfilled

audit-module

PAYROLL

audit-action

CREATE

audit-trigger

Once per backfill run, summarising its counts instead of one entry per value

elementClassifiedLog()

Log a payroll element classified

public static elementClassifiedLog(mixed $record, string $attributeCode[, int $userId = 0 ]) : void
Parameters
$record : mixed

The new ElementAttributeValue data

$attributeCode : string

The attribute's code

$userId : int = 0

The ID of the user who performed the action (optional)

Tags
audit-event

Element Classified

audit-module

PAYROLL

audit-action

CREATE

audit-trigger

When an element is given a value for an attribute it had none for

elementReclassifiedLog()

Log a payroll element reclassified

public static elementReclassifiedLog(mixed $oldRecord, mixed $newRecord, string $attributeCode[, int $userId = 0 ]) : void
Parameters
$oldRecord : mixed

The replaced ElementAttributeValue data, carrying the reason

$newRecord : mixed

The new ElementAttributeValue data

$attributeCode : string

The attribute's code

$userId : int = 0

The ID of the user who performed the action (optional)

Tags
audit-event

Element Reclassified

audit-module

PAYROLL

audit-action

UPDATE

audit-trigger

When an element's live value for an attribute is replaced by a different value

addAuditLog()

Log an audit trail entry

protected static addAuditLog(int|null $companyId, int $userId, string $message, string $module, string $action[, mixed|null $currentRecord = null ][, mixed|null $updatedRecord = null ][, string|null $objectName = null ][, string $queueName = 'audit-trails' ][, bool $afterCommit = false ][, string $type = AuditTypesEnum::COMPANY->value ]) : void
Parameters
$companyId : int|null

Company identifier, null for records that belong to no company (e.g. global payroll elements)

$userId : int

User identifier (default 0 for system actions)

$message : string

Human-readable audit message

$module : string

Module name (PAYROLL, LEAVE, PAYMENTS, etc.) - must be a valid AuditModulesEnum value

$action : string

Action type (CREATE, UPDATE, DELETE, etc.) - must be a valid AuditActionsEnum value

$currentRecord : mixed|null = null

Current data being logged

$updatedRecord : mixed|null = null

The updated data (for updates)

$objectName : string|null = null

Optional name of the object being logged - if not provided, will be inferred from the model

$queueName : string = 'audit-trails'

Optional queue name for async processing. Default 'audit-trails'

$afterCommit : bool = false

Whether to log after DB commit

$type : string = AuditTypesEnum::COMPANY->value
Tags
throws
ValueError

If invalid enum values are provided

getCompanyId()

Extract company ID from various model types.

protected static getCompanyId(mixed $model) : int

This method attempts to determine the company ID from the provided model instance.

It checks for a direct company_id property or navigates through related employee models.

Parameters
$model : mixed

Model instance

Tags
throws
Exception

When company ID cannot be determined

Return values
int —

Company ID

getUserId()

Get the current authenticated user ID, or fallback to job context user ID.

protected static getUserId() : int

This method first checks for an authenticated user via the auth() helper. If no user is authenticated, it looks for a user_id in the job context (for queued jobs).

To add a user ID to the job context, you can use this in your job setup:

 app()->instance('job_context', ['user_id' => $userId]);

If neither is available, it returns 0 to indicate a system action.

Return values
int —

The determined user ID, or 0 if none found


        
On this page

Search results