Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

timyboy12345's avatar

What is the best way to develop subdomains in Laravel?

I'm creating a website in which I want an admin panel and a panel for schools. This second panel should be available trough "school.{DOMAIN}". Currently, these are two separate projects that both have the same models and migrations, but I have to add/change the files in both projects when I change a model, notification or something else.

This means that development can be very annoying because I have to copy/paste files between projects. This is why I'm interested in Laravel subdomain routing. However, the more I read into this method, the more I am starting to think Laravel subdomain routing isn't quite a finished project yet. I've got a few questions:

1: How should I add the subdomain to my Routes, I currently have

    protected function mapSchoolRoutes()
    {
        Route::domain('school.lvh.me')
            ->namespace($this->namespace)
            ->group(base_path('routes/school.php'));
    }

in my RouteServiceProvider.php file, but this way when I deploy to production, it is still only responding to requests to .lvh.me (which doesn't work, because this isn't the domain).

2: Can I use separate login/register pages for my subdomain? Currently, when I add Auth::routes() to my routes/school.php file, it goes to the default views (views/auth/login.php) instead of the right files (views/school/auth/login.php).

3: Is Laravel subdomain development "mature" enough? Or is there a better way for me to develop the main domain and a subdomain?

0 likes
4 replies
jove's avatar

Subdomains sure works, I did use it before. From that I learned that I don't want to work with that and instead just split the admin to a /a/ or /admin/, which is what I do now.

Auth::routes() will go to the default as that is what the routes tell it to, you need to create your own routes for a second login.

timyboy12345's avatar

Creating a /school is a possibility, but I prefer to create a separate subdomain. That way, Authentication is easier and I can do things like better SEO that I can't do when it's all on one domain.

My current solution is two projects, but these have separate models. I was wondering if someone has a good solution for "sharing" models between two Laravel projects. This way, I wouldn't have to copy/paste files every time I change a model or notification.

A custom authentication system isn't too big of a problem, so this could be a possibility. Then I would still have the problem of the subdomain route mapping in local and production environments. I don't want to change a file before I merge/commit. The best solution I could think of is checking if env("APP_TYPE") is dev or prod, and change the domain based on that. But if anyone has a better solution, please feel free to share it with me!

topvillas's avatar

Create a package that contains your models then each time you update them, you just have to do a composer update.

jove's avatar

I would stick to one project instead of some custom weird cross project dependencies

Please or to participate in this conversation.