Skip to content

auditledge/auditledge-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

auditledge-php

Official PHP SDK for Auditledge — the audit log API for SaaS developers.

Install

composer require auditledge/auditledge-php

Quickstart

use 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']);

Laravel Example

// 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();
    }
}

Links

License

MIT

About

PHP SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages