PHP code example of glueful / audit

1. Go to this page and download the library: Download glueful/audit 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/ */

    

glueful / audit example snippets


use Glueful\Events\Contracts\BaseEvent;
use Glueful\Extensions\Audit\Contracts\{AuditableEvent, AuditableEventDefaults};

final class EntryPublished extends BaseEvent implements AuditableEvent
{
    use AuditableEventDefaults; // defaults for target/changes/metadata — override as needed

    public function __construct(
        public readonly string $entryUuid,
        public readonly string $title,
    ) {
        parent::__construct();
    }

    public function auditAction(): string   { return 'published'; }
    public function auditCategory(): string { return 'content'; }
    public function auditTarget(): array
    {
        return ['type' => 'content_entry', 'uuid' => $this->entryUuid, 'label' => $this->title];
    }
}

// Anywhere you already dispatch events:
$this->events->dispatch(new EntryPublished($uuid, $title));

app($context, AuditRecorderInterface::class)->record(new AuditEntry(
    occurredAt: microtime(true),
    action: 'exported',
    category: 'data',
    // … actor/target/changes/context …
));
bash
composer extensions:enable audit
php glueful migrate:run
bash
GET /v1/audit-logs?actor=<uuid>&action=role_assigned&from=2026-06-01&to=2026-06-30