Initial commit
This commit is contained in:
21
app/Support/AuditLogger.php
Normal file
21
app/Support/AuditLogger.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user