PHP code example of azaharizaman / nexus-audit-logger

1. Go to this page and download the library: Download azaharizaman/nexus-audit-logger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

azaharizaman / nexus-audit-logger example snippets


use Nexus\AuditLogger\Contracts\AuditLogRepositoryInterface;

class DbAuditLogRepository implements AuditLogRepositoryInterface
{
    // Implement all contract methods using your persistence layer
}

use Nexus\AuditLogger\Services\AuditLogManager;

$auditManager = new AuditLogManager($repository, $config);

$auditManager->log(
    logName: 'user_update',
    description: 'User profile updated',
    subjectType: 'User',
    subjectId: 123,
    causerType: 'User',
    causerId: 456,
    properties: ['old' => [...], 'new' => [...]],
    level: 3, // High
    batchUuid: 'uuid-here'
);

$searchService = new AuditLogSearchService($repository);

$logs = $searchService->search([
    'date_from' => '2025-01-01',
    'date_to' => '2025-12-31',
    'causer_id' => 456,
    'subject_type' => 'User',
    'level' => 4, // Critical
    'log_name' => 'user_update'
]);

$exportService = new AuditLogExportService($repository);

$csv = $exportService->exportToCsv($filters);
$json = $exportService->exportToJson($filters);
$pdf = $exportService->exportToPdf($filters);