authorize('update', $event); abort_unless($this->service->enabled(), 404); $data = $request->validate([ 'host' => ['required', 'string', 'max:255', 'regex:/^(?!-)([a-z0-9-]+\.)+[a-z]{2,}$/i'], 'include_www' => ['nullable', 'boolean'], ]); $host = strtolower(preg_replace('/^www\./', '', trim($data['host']))); if (CustomDomain::where('host', $host)->exists()) { return back()->withErrors(['host' => 'That domain is already connected.']); } $this->service->attach($event, $host, (bool) ($data['include_www'] ?? true)); return back()->with('success', "Domain added. Point an A record for {$host} (and www) to ".config('customdomain.server_ip').', then click Verify.'); } public function verify(Request $request, CustomDomain $customDomain): RedirectResponse { $this->authorize('update', $customDomain->qrCode); [$ok, $message] = $this->service->verifyAndProvision($customDomain); return back()->with($ok ? 'success' : 'error', $message); } public function destroy(Request $request, CustomDomain $customDomain): RedirectResponse { $this->authorize('update', $customDomain->qrCode); $customDomain->delete(); return back()->with('success', 'Custom domain removed.'); } }