PHP code example of digit7s / laravel-audit-toolkit

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

    

digit7s / laravel-audit-toolkit example snippets


use Illuminate\Support\Facades\Auth;

audit()->recordEvent(
    event: 'order.status.changed',
    actor: Auth::user(),
    subject: $order,
    oldValues: ['status' => 'pending'],
    newValues: ['status' => 'paid'],
    allowedValueKeys: ['status'],
    category: 'business',
    source: 'http',
);

use Digit7s\AuditToolkit\Concerns\Auditable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Auditable;

    protected function auditInclude(): array
    {
        return ['title', 'status', 'published_at'];
    }
}

use Digit7s\AuditToolkit\Queue\AuditContextMiddleware;

final class RebuildSearchIndex
{
    public function middleware(): array
    {
        return [AuditContextMiddleware::fromCurrent()];
    }
}

'authentication' => [
    'enabled' => true,
    'events' => ['login', 'logout', 'failed', 'password_reset', 'email_verified'],
],

audit_context()->withImpersonation($administrator, function () use ($effectiveUser, $order): void {
    audit()->recordEvent('order.approved', actor: $effectiveUser, subject: $order);
}, $effectiveUser);

use Digit7s\AuditToolkit\Contracts\AuditQuery;

$events = app(AuditQuery::class)
    ->newQuery()
    ->where('event', 'order.status.changed')
    ->latest('occurred_at')
    ->paginate();
bash
php artisan vendor:publish --tag=audit-toolkit-config
php artisan vendor:publish --tag=audit-toolkit-migrations
php artisan migrate