In this episode, we tackle adding custom subdomains for users during the registration process of our app. We start off with a quick cleanup by deleting the previous user and their related data to ensure we're starting from scratch.
Next, we jump into modifying the registration form by adding a new field that lets users pick their desired subdomain. We walk through the tweaks needed in the Blade template to make the input look nice, complete with the primary domain shown alongside the subdomain for clarity. There’s also a bit of string manipulation to ensure the URL looks clean and professional.
With the UI changes in place, we move to the backend. We update the registration logic to validate and store the new subdomain, including adding a migration to give the users table a subdomain
column (with uniqueness enforced). We also set up all the right validation rules to make sure subdomains are alphanumeric and unique, and adjust the user model to accommodate the new field.
Once registration is working, we don’t stop there. We then update the profile page to allow users to edit their subdomain after registration. This covers updating the form and tweaking the relevant controllers and request validation logic, including using more advanced Laravel validation rules to let users keep their current subdomain without running into uniqueness errors.
By the end of the episode, users can pick and update their subdomain seamlessly, with proper validation and database support behind the scenes.