$account->linkCustomDomains()->latest()->get(), 'enabled' => $this->service->enabled(), 'serverIp' => (string) config('customdomain.server_ip'), 'publicDomain' => (string) config('link.public_domain', 'ladl.link'), ]); } public function store(Request $request): RedirectResponse { 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'], 'make_default' => ['nullable', 'boolean'], ]); $host = strtolower(preg_replace('/^www\./', '', trim($data['host']))); if (LinkCustomDomain::where('host', $host)->exists()) { return back()->withErrors(['host' => 'That domain is already connected.']); } $domain = $this->service->attach( $request->user(), $host, (bool) ($data['include_www'] ?? true), (bool) ($data['make_default'] ?? false), ); $this->domains->registerConnected( $host, (string) $request->user()->public_id, 'Ladill Link', route('link.domains.index'), ); return back()->with('success', "Domain added. Point an A record for {$host} to ".config('customdomain.server_ip').', then click Verify.'); } public function verify(Request $request, LinkCustomDomain $customDomain): RedirectResponse { abort_unless($customDomain->user_id === $request->user()->id, 403); [$ok, $message] = $this->service->verifyAndProvision($customDomain); return back()->with($ok ? 'success' : 'error', $message); } public function makeDefault(Request $request, LinkCustomDomain $customDomain): RedirectResponse { abort_unless($customDomain->user_id === $request->user()->id, 403); abort_unless($customDomain->isLive(), 422); $this->service->setDefault($customDomain); return back()->with('success', $customDomain->host.' is now your default short-link domain.'); } public function destroy(Request $request, LinkCustomDomain $customDomain): RedirectResponse { abort_unless($customDomain->user_id === $request->user()->id, 403); $host = $customDomain->host; $customDomain->delete(); $this->domains->removeConnected($host); return back()->with('success', 'Custom domain removed.'); } }