user()->isAdmin()) { abort(403); } } public function index(): View { $this->authorizeAdmin(); $registered = $this->supportService->isRegistered(); $tickets = $registered ? ($this->supportService->getTickets() ?? []) : []; return view('admin.support.index', compact('registered', 'tickets')); } public function show(int $ticketId): View|RedirectResponse { $this->authorizeAdmin(); if (!$this->supportService->isRegistered()) { return redirect()->route('admin.support.index'); } $ticket = $this->supportService->getTicket($ticketId); if (!$ticket) { return redirect()->route('admin.support.index') ->with('error', __('admin.support_ticket_not_found')); } return view('admin.support.show', compact('ticket')); } public function store(Request $request): RedirectResponse { $this->authorizeAdmin(); $request->validate([ 'subject' => 'required|string|max:255', 'message' => 'required|string|max:5000', 'category' => 'required|string|in:bug,feature,question,other', ]); $result = $this->supportService->createTicket([ 'subject' => $request->input('subject'), 'message' => $request->input('message'), 'category' => $request->input('category'), 'system_info' => $this->supportService->getSystemInfo(), 'license_key' => Setting::get('license_key'), ]); if (!$result) { return back()->withInput() ->with('error', __('admin.support_submit_failed')); } return redirect()->route('admin.support.show', $result['ticket_id'] ?? 0) ->with('success', __('admin.support_ticket_created')); } public function reply(Request $request, int $ticketId): RedirectResponse { $this->authorizeAdmin(); $request->validate([ 'message' => 'required|string|max:5000', ]); $result = $this->supportService->replyToTicket($ticketId, [ 'message' => $request->input('message'), ]); if (!$result) { return back()->withInput() ->with('error', __('admin.support_reply_failed')); } return redirect()->route('admin.support.show', $ticketId) ->with('success', __('admin.support_reply_sent')); } public function register(): RedirectResponse { $this->authorizeAdmin(); $data = [ 'app_name' => Setting::get('app_name', config('app.name')), 'app_url' => config('app.url'), 'app_version' => config('app.version'), 'php_version' => PHP_VERSION, 'db_driver' => config('database.default'), 'installed_at' => $this->supportService->readInstalled()['installed_at'] ?? now()->toIso8601String(), ]; $logoUrl = $this->supportService->getLogoUrl(); if ($logoUrl) { $data['logo_url'] = $logoUrl; } $result = $this->supportService->register($data); if ($result) { return back()->with('success', __('admin.registration_success')); } return back()->with('error', __('admin.registration_failed')); } }