22 lines
522 B
PHP
22 lines
522 B
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Models\AuditLog;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class AuditLogger
|
|
{
|
|
public static function log(string $action, ?object $auditable = null, array $metadata = []): void
|
|
{
|
|
AuditLog::create([
|
|
'user_id' => optional(Auth::user())->id,
|
|
'action' => $action,
|
|
'auditable_type' => $auditable ? get_class($auditable) : null,
|
|
'auditable_id' => $auditable->id ?? null,
|
|
'metadata' => $metadata,
|
|
]);
|
|
}
|
|
}
|
|
|