In this episode, we're making it possible for users to choose their own subdomain as part of their profile. We start out by updating the profile form so users can actually enter their preferred subdomain. We just duplicate the email input field, switch everything over to use "subdomain," and do a bit of cleanup to make sure it's all set up properly (removing autofocus, autocomplete, and the required attribute).
After that, we move on to validation. We jump into our form request and add validation rules—making sure the subdomain is a string, contains only letters (no numbers or special characters), and most importantly, that it's unique to the user. We also set it up so if the user already has a subdomain and tries saving it again, it doesn't error out, since that's theirs.
Finally, we tweak our User model to allow the subdomain field to be updated. Now, when we save the profile, the subdomain is stored and validated. If another user tries to pick the same subdomain, they'll see an error, keeping things nice and unique. So now, our users have their own custom subdomains, and the validation has their back!