Files
2025-11-30 11:57:22 +01:00

32 lines
877 B
PHP

<?php
namespace Paymenter\Extensions\Others\ComplianceTools\Services;
use App\Models\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Auth;
use Paymenter\Extensions\Others\ComplianceTools\Models\AuditLog;
class AuditLogService
{
public static function record(
string $category,
string $event,
array $context = [],
?User $subject = null,
Authenticatable|User|null $actor = null
): AuditLog {
$actor ??= Auth::user();
return AuditLog::create([
'category' => $category,
'event' => $event,
'subject_user_id' => $subject?->getKey(),
'actor_type' => $actor?->getMorphClass(),
'actor_id' => $actor?->getAuthIdentifier(),
'ip_address' => request()->ip(),
'context' => $context,
]);
}
}