32 lines
867 B
PHP
32 lines
867 B
PHP
<?php
|
|
|
|
namespace App\Services\Admin;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class AdminAuditService
|
|
{
|
|
public function log(
|
|
int $actorAdminId,
|
|
string $action,
|
|
string $targetType,
|
|
int $targetId,
|
|
?array $before,
|
|
?array $after,
|
|
string $ip = '',
|
|
string $ua = '',
|
|
): void {
|
|
DB::table('admin_audit_logs')->insert([
|
|
'actor_admin_user_id' => $actorAdminId,
|
|
'action' => $action,
|
|
'target_type' => $targetType,
|
|
'target_id' => $targetId,
|
|
'before_json' => $before ? json_encode($before, JSON_UNESCAPED_UNICODE) : null,
|
|
'after_json' => $after ? json_encode($after, JSON_UNESCAPED_UNICODE) : null,
|
|
'ip' => $ip ?: null,
|
|
'user_agent' => $ua ?: null,
|
|
'created_at' => now(),
|
|
]);
|
|
}
|
|
}
|