resetPage(); } public function updatedTargetFilter(): void { $this->resetPage(); } public function updatedDateFrom(): void { $this->resetPage(); } public function updatedDateTo(): void { $this->resetPage(); } public function updatedSearch(): void { $this->resetPage(); } public function resetFilters(): void { $this->reset(['actionFilter', 'targetFilter', 'dateFrom', 'dateTo', 'search']); $this->resetPage(); } public function showDetails(int $logId): void { $this->selectedLogId = $logId; $this->dispatch('open-modal', name: 'log-details'); } public function closeModal(): void { $this->selectedLogId = null; $this->dispatch('close-modal', name: 'log-details'); } public function exportCsv(): StreamedResponse { $logs = $this->getFilteredQuery()->get(); return response()->streamDownload(function () use ($logs) { $handle = fopen('php://output', 'w'); // Header row (bilingual based on locale) fputcsv($handle, [ __('audit.timestamp'), __('audit.admin'), __('audit.action'), __('audit.target_type'), __('audit.target_id'), __('audit.ip_address'), ]); foreach ($logs as $log) { fputcsv($handle, [ $log->created_at->format('Y-m-d H:i:s'), $log->admin?->name ?? __('audit.system'), $log->action, $log->target_type, $log->target_id, $log->ip_address, ]); } fclose($handle); }, 'audit-log-' . now()->format('Y-m-d') . '.csv'); } public function with(): array { return [ 'logs' => $this->getFilteredQuery()->paginate(25), 'actionTypes' => AdminLog::distinct()->pluck('action'), 'targetTypes' => AdminLog::distinct()->pluck('target_type'), 'selectedLog' => $this->selectedLogId ? AdminLog::with('admin')->find($this->selectedLogId) : null, ]; } private function getFilteredQuery() { return AdminLog::query() ->with('admin') ->when($this->actionFilter, fn ($q) => $q->where('action', $this->actionFilter)) ->when($this->targetFilter, fn ($q) => $q->where('target_type', $this->targetFilter)) ->when($this->dateFrom, fn ($q) => $q->whereDate('created_at', '>=', $this->dateFrom)) ->when($this->dateTo, fn ($q) => $q->whereDate('created_at', '<=', $this->dateTo)) ->when($this->search, fn ($q) => $q->where('target_id', $this->search)) ->latest('created_at'); } private function getActionColor(string $action): string { return match ($action) { 'create', 'approve' => 'green', 'update', 'status_change' => 'blue', 'delete', 'reject' => 'red', 'archive' => 'amber', default => 'zinc', }; } }; ?>
{{ __('audit.audit_logs_description') }}
{{ $actionFilter || $targetFilter || $dateFrom || $dateTo || $search ? __('audit.no_results') : __('audit.no_logs_found') }}
{{ json_encode($selectedLog->old_values, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) }}
{{ json_encode($selectedLog->new_values, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) }}