1. Go to this page and download the library: Download getimmutable/laravel 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/ */
use GetImmutable\AuditLog;
// Uses the currently authenticated user as the actor
AuditLog::fromAuth()->track('project.created', $project, [
'ip' => request()->ip(),
]);
use GetImmutable\AuditLog;
AuditLog::actor($user)->track('invoice.paid', $invoice, [
'amount' => 9900,
]);
// Eloquent model
AuditLog::fromAuth()->track('project.deleted', $project);
// Plain string
AuditLog::fromAuth()->track('report.exported', 'Report');
// No resource
AuditLog::fromAuth()->track('user.logged_in');
use GetImmutable\Concerns\TracksEvents;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
use TracksEvents;
}
class Project extends Model
{
use TracksEvents;
protected static array $trackedEvents = ['created', 'deleted'];
}
use GetImmutable\AuditLog;
use GetImmutable\Jobs\SendAuditLogEvent;
use Illuminate\Support\Facades\Queue;
Queue::fake();
AuditLog::track(['actor_id' => 'test', 'action' => 'test.action']);
Queue::assertPushed(SendAuditLogEvent::class);