'mybrand', 'email' => 'me@example.com']); * echo $claim->claim_id; */ class SubmitClaim { public function __construct( private readonly DaemonRpc $rpc, ) {} public function handle(array $data): NameClaim { $name = strtolower(trim($data['name'] ?? '')); $email = trim($data['email'] ?? ''); $this->validate($name, $email); $claim = NameClaim::create([ 'name' => $name, 'email' => $email, ]); NameActivity::log($name, 'claimed', [ 'claim_id' => $claim->claim_id, 'email' => $email, ], request()?->ip()); return $claim; } private function validate(string $name, string $email): void { if (! preg_match('/^[a-z0-9][a-z0-9.\-]{0,254}$/', $name)) { throw ValidationException::withMessages([ 'name' => 'Invalid name. Use lowercase alphanumeric characters.', ]); } if (strlen($name) < 6) { throw ValidationException::withMessages([ 'name' => 'Name must be at least 6 characters.', ]); } if (empty($email) || ! filter_var($email, FILTER_VALIDATE_EMAIL)) { throw ValidationException::withMessages([ 'email' => 'Valid email required for claim notification.', ]); } // Not already registered on chain if ($this->rpc->getAliasByName($name) !== null) { throw ValidationException::withMessages([ 'name' => 'Name already registered.', ]); } // Not already claimed if (NameClaim::where('name', $name)->exists()) { throw ValidationException::withMessages([ 'name' => 'Name already claimed. Awaiting approval.', ]); } } public static function run(array $data): NameClaim { return app(static::class)->handle($data); } }