1. Go to this page and download the library: Download hosmelq/laravel-audit-logs 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/ */
hosmelq / laravel-audit-logs example snippets
use function HosmelQ\AuditLog\audit_log;
audit_log('document.published')
->tenant('org_123')
->record();
use function HosmelQ\AuditLog\audit_log;
audit_log('document.published')
->tenant('org_123')
->actor(type: 'user', id: 'member_123')
->target(type: 'document', id: 'doc_123')
->metadata(['visibility' => 'public'])
->record();
use function HosmelQ\AuditLog\audit_log;
$log = audit_log('document.published')
->tenant('org_123')
->target(type: 'document', id: 'doc_123')
->toAuditLogData();
audit_log()->record($log);
use HosmelQ\AuditLog\Facades\AuditLog;
AuditLog::record($log);
use function HosmelQ\AuditLog\audit_log;
audit_log()->record([
audit_log('document.published')->tenant('org_123')->toAuditLogData(),
audit_log('notification.sent')->tenant('org_123')->toAuditLogData(),
]);
use function HosmelQ\AuditLog\audit_log;
audit_log()->correlate(function (): void {
audit_log('document.published')
->target(type: 'document', id: 'doc_123')
->record();
audit_log('notification.sent')
->target(type: 'document', id: 'doc_123')
->record();
});
use function HosmelQ\AuditLog\audit_log;
enum AuditEvent: string
{
case DocumentPublished = 'document.published';
}
audit_log(AuditEvent::DocumentPublished)
->tenant('org_123')
->record();
use HosmelQ\AuditLog\Models\AuditLog;
use Illuminate\Support\Facades\Schedule;
Schedule::command('model:prune', [
'--model' => [AuditLog::class],
])->daily();
namespace App\Models;
use HosmelQ\AuditLog\Models\AuditLog as BaseAuditLog;
class AuditLog extends BaseAuditLog
{
}
use App\Models\AuditLog;
use HosmelQ\AuditLog\DatabaseAuditLogManager;
DatabaseAuditLogManager::useModel(AuditLog::class);
use HosmelQ\AuditLog\Facades\AuditLog;
use function HosmelQ\AuditLog\audit_log;
AuditLog::fake();
audit_log('document.published')
->tenant('org_123')
->record();
AuditLog::assertRecorded('document.published');