Playing
01. Introduction and demo

Transcript

00:00
Allowing your users to choose custom subdomains is actually pretty straightforward in Laravel. And in this course I'm going to guide you through how we set this up. We're going to do this within a Laravel Breeze app just because Laravel Breeze gives us the ability to update our profile information, gives us our authentication scaffolding and makes things a lot easier.
00:19
Although you can transfer anything in this course over to any Laravel app regardless of how you set it up. So let's take a look. I'm going to go over to the profile section here and I've added in this subdomain field. The moment I don't have one but I can go ahead and choose one.
00:34
Now of course this needs to be unique. Two users can't have the same subdomain and we can't have things like special characters in the subdomain either. We just want this to be plain text. So I'm going to go ahead and save this out and that's done.
00:48
I now have my own subdomain within this app. So I'm going to go ahead and get rid of profile on the end of here. I'm going to head straight over to alex. and then whichever domain that we're running our app on. If I go ahead and run this, sure enough we are now into my own area within this app.
01:06
So this is directly pulled from the database. We look the user up by their subdomain, pass that information down and now we can extract any information about that user that we want. We can also switch between pages within this specific domain and this is only valid for this domain. If we go back to our main app, it doesn't exist.
01:27
It just exists for any users that have added a subdomain. Now on the flip side of this, we're also going to disable any of the standard routes that we would find in our main app for any subdomains that we create. You can see that if we go over to slash dashboard on alex. and then the domain that we're using, it doesn't work. If we head back over to our main app, sure enough it does.
01:49
So although this is pretty simple to implement within Laravel, we're going to go through this step by step and talk about some of the issues that you might come up against. How to do this in the cleanest way possible. And at the end of the course, we're also going to deploy this so you can see how you can get this live and working for users in your app. Okay, let's head over to the next episode where we're going to set up a fresh app and get this subdomain column in the users table so we can start to allow users to choose their own subdomains.

Episode summary

Welcome to the course! In this introduction episode, we jump right into what the course is all about—letting users in a Laravel app pick their own custom subdomains. We'll use Laravel Breeze to keep things simple, since it handles authentication and user profiles for us, but everything we cover can be used in any Laravel project.

I show you a demo of the subdomain feature: users can add a unique subdomain to their profile (with all the necessary checks like uniqueness and character restrictions), and once saved, they can visit their own area of the app via their new subdomain. This is all powered by looking up users by their subdomain from the database, and it only works for users who have set one up—otherwise, the subdomain-based routes just don't exist.

We also make sure that things like the main dashboard and other usual routes are protected on subdomain URLs, so your app's main navigation doesn't just pop up everywhere it shouldn't.

Throughout the series, we'll go step by step to make this clean and robust, talking about gotchas, best practices, and finally, deploying the app so you can see it live. In the next episode, we'll get hands-on by setting up the app and getting that all-important subdomain column ready. Let's get started!

Episode discussion

No comments, yet. Be the first!