Official PHP SDK for Auditledge — the audit log API for SaaS developers.
composer require auditledge/auditledge-phpuse Auditledge\AuditLedge;
$client = new AuditLedge('your_api_key');
// Log an event
$client->log([
'actor' => ['id' => 'user_123', 'name' => 'Alice', 'email' => 'alice@example.com'],
'action' => 'invoice.deleted',
'resource' => ['type' => 'invoice', 'id' => 'inv_456'],
'organization_id' => 'org_789',
'metadata' => ['ip' => $_SERVER['REMOTE_ADDR']]
]);
// Query events
$events = $client->query(['organization_id' => 'org_789', 'limit' => 50]);
// Export
$csv = $client->export(['format' => 'csv', 'organization_id' => 'org_789']);// In your controller
use Auditledge\AuditLedge;
class InvoiceController extends Controller
{
private AuditLedge $audit;
public function __construct()
{
$this->audit = new AuditLedge(config('services.auditledge.key'));
}
public function destroy(Invoice $invoice)
{
$invoice->delete();
$this->audit->log([
'actor' => ['id' => auth()->id(), 'name' => auth()->user()->name],
'action' => 'invoice.deleted',
'resource' => ['type' => 'invoice', 'id' => $invoice->id],
'organization_id' => auth()->user()->organization_id,
]);
return response()->noContent();
}
}MIT