user_id === $request->user()->id, 403); 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($storefront, $host, (bool) ($data['include_www'] ?? true)); // Surface this domain in Ladill Domains' "My Domains" (best-effort). $this->domains->registerConnected( $host, (string) $request->user()->public_id, 'Storefront: '.$storefront->label, route('merchant.storefronts.show', $storefront), ); 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 { abort_unless($customDomain->user_id === $request->user()->id, 403); [$ok, $message] = $this->service->verifyAndProvision($customDomain); return back()->with($ok ? 'success' : 'error', $message); } public function destroy(Request $request, CustomDomain $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.'); } }