Documentation for AuditLedge — production-grade audit logs for SaaS
The official PHP SDK for AuditLedge.
composer require auditledge/auditledge-php
use Auditledge\AuditLedge;
$client = new AuditLedge('your_api_key');
Store your API key in an environment variable:
$client = new AuditLedge($_ENV['AUDITLEDGE_API_KEY']);
$client->log([
'actor' => [
'id' => 'user_123',
'name' => 'Alice',
'email' => 'alice@example.com'
],
'action' => 'invoice.deleted',
'resource' => [
'type' => 'invoice',
'id' => 'inv_456',
'name' => 'Invoice #1042'
],
'organization_id' => 'org_789',
'metadata' => ['ip' => $_SERVER['REMOTE_ADDR']]
]);
Required fields: actor.id, action, resource.type, resource.id
$events = $client->query([
'organization_id' => 'org_789',
'actor_id' => 'user_123',
'action' => 'invoice.deleted',
'from' => '2026-01-01T00:00:00Z',
'limit' => 50,
'offset' => 0
]);
$csv = $client->export([
'format' => 'csv',
'organization_id' => 'org_789'
]);
$json = $client->export([
'format' => 'json',
'organization_id' => 'org_789'
]);
Supported formats: csv, json
public function destroy(Invoice $invoice)
{
$invoice->delete();
app('auditledge')->log([
'actor' => [
'id' => (string) auth()->id(),
'name' => auth()->user()->name
],
'action' => 'invoice.deleted',
'resource' => ['type' => 'invoice', 'id' => (string) $invoice->id],
'organization_id' => (string) auth()->user()->organization_id,
'metadata' => ['ip' => request()->ip()]
]);
return redirect()->route('invoices.index');
}
Use dot notation: resource.action
user.created user.updated user.deleted
invoice.sent invoice.paid invoice.voided
subscription.started subscription.upgraded subscription.cancelled
api_key.created api_key.revoked