user(); abort_unless($user !== null && method_exists($user, 'isAdmin') && $user->isAdmin(), 403); abort_unless((int) $comment->ticket_id === (int) $ticket->id, 404); DB::transaction(function () use ($comment, $ticket, $user): void { $updates = []; if (Schema::hasColumn('helpdesk_comments', 'tombstoned_at')) { $updates['tombstoned_at'] = now(); } if (Schema::hasColumn('helpdesk_comments', 'deleted_by')) { $updates['deleted_by'] = (int) $user->id; } if (Schema::hasColumn('helpdesk_comments', 'delete_reason')) { $updates['delete_reason'] = 'Deleted by Thredary platform administrator.'; } if (Schema::hasColumn('helpdesk_comments', 'sync_sequence')) { $updates['sync_sequence'] = ((int) ($comment->sync_sequence ?? 0)) + 1; } if (Schema::hasColumn('helpdesk_comments', 'sync_hash')) { $updates['sync_hash'] = hash('sha256', implode('|', [ (string) ($comment->guid ?? $comment->id), 'deleted', now()->toISOString(), ])); } if (Schema::hasColumn('helpdesk_comments', 'updated_at')) { $updates['updated_at'] = now(); } if ($updates !== []) { DB::table('helpdesk_comments') ->where('id', $comment->id) ->update($updates); } else { $comment->delete(); } if (Schema::hasColumn('helpdesk_tickets', 'last_activity_at')) { $ticket->forceFill(['last_activity_at' => now()])->save(); } }); return redirect() ->route('helpdesk.tickets.show', $ticket) ->with('ticket-comment-deleted', 'Response deleted.'); } }