PHP code example of tofiq / laravel-audit-trail

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

    

tofiq / laravel-audit-trail example snippets



return [
    ...

    'audit_model' => \App\Models\YourAuditTrailModel::class,
    ...
];



namespace App\Services;

use Tofiq\AuditTrail\Contracts\AuditLoggerInterface;

class MyLogService implements AuditLoggerInterface
{
    public function log(string|null $tableName, string $operationType, string $query, array $bindings = [], int|float $time = 0): void
    {
        \Log::info('Query Logged', [
            'table' => $tableName,
            'operation' => $operationType,
            'query' => $query,
            'bindings' => $bindings,
            'execution_time' => $time,
        ]);
    }
}

    public function boot(): void
    {
        $this->app->bind(
            \Tofiq\AuditTrail\Contracts\AuditLoggerInterface::class,
            \App\Services\MyLogService::class
        );
    }
bash
php artisan vendor:publish --provider=Tofiq\\AuditTrail\\AuditTrailServiceProvider
bash
php artisan migrate