first
This commit is contained in:
35
app/Services/AuditLogService.php
Normal file
35
app/Services/AuditLogService.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\AuditLog;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AuditLogService
|
||||
{
|
||||
public function __construct(private readonly Request $request) {}
|
||||
|
||||
public function log(
|
||||
string $action,
|
||||
array $options = []
|
||||
): AuditLog {
|
||||
$actor = Auth::user();
|
||||
|
||||
return AuditLog::create([
|
||||
'actor_user_id' => $actor?->id ?? $options['actor_user_id'] ?? null,
|
||||
'actor_role' => $actor?->role ?? $options['actor_role'] ?? 'system',
|
||||
'action' => $action,
|
||||
'subject_type' => $options['subject_type'] ?? null,
|
||||
'subject_id' => $options['subject_id'] ?? null,
|
||||
'target_user_id'=> $options['target_user_id'] ?? null,
|
||||
'project_id' => $options['project_id'] ?? null,
|
||||
'old_values' => $options['old_values'] ?? null,
|
||||
'new_values' => $options['new_values'] ?? null,
|
||||
'justification' => $options['justification'] ?? null,
|
||||
'ip_address' => $this->request->ip(),
|
||||
'user_agent' => $this->request->userAgent(),
|
||||
'created_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user