public_id; } public function index(): View { $domains = []; $error = null; try { $domains = $this->domains->forUser($this->pid()); } catch (\Throwable $e) { report($e); $error = 'Could not load your domains.'; } return view('email.domains.index', compact('domains', 'error')); } public function store(Request $request): RedirectResponse { $data = $request->validate(['domain' => ['required', 'string', 'max:253']]); try { $domain = $this->domains->create($this->pid(), strtolower(trim($data['domain']))); return redirect()->route('email.domains.show', $domain['id']) ->with('success', 'Domain added — publish the DNS records below, then verify.'); } catch (\Throwable $e) { report($e); return back()->with('error', 'Could not add that domain. It may already exist.'); } } public function show(int $id): View|RedirectResponse { try { $domain = $this->domains->show($this->pid(), $id); } catch (\Throwable $e) { return redirect()->route('email.domains.index')->with('error', 'Domain not found.'); } return view('email.domains.show', ['domain' => $domain]); } public function verify(int $id): RedirectResponse { try { $domain = $this->domains->verify($this->pid(), $id); $ok = $domain['active'] ?? false; return redirect()->route('email.domains.show', $id) ->with($ok ? 'success' : 'error', $ok ? 'Domain verified — you can now create mailboxes.' : 'Not verified yet. DNS can take time to propagate.'); } catch (\Throwable $e) { return back()->with('error', 'Verification failed. Try again shortly.'); } } public function destroy(int $id): RedirectResponse { try { $this->domains->delete($this->pid(), $id); } catch (\Throwable $e) { return back()->with('error', 'Could not remove that domain.'); } return redirect()->route('email.domains.index')->with('success', 'Domain removed.'); } }