Home > Mobile >  Laravel application: Do I need a new application for new subdomain?
Laravel application: Do I need a new application for new subdomain?

Time:03-02

In my server, I had a shop.mycompany.com folder and I built a Laravel application inside it for handling the shopping related process. So, ppl can access shop.mycompany.com/item?name=asdf to shop. I think shop.mycompany.com is a subdomain of mycompany.com, please correct me if I am wrong.

I would like to have another subdomain, comment.mycompany.com, to handle customers' comments. Maybe I will send a mail to customer with the link comment.mycompany.com/customer?id=1, so they can leave there comment.

My question is can I use the Laravel application in shop.mycompany.com folder to build the comment.mycompany.com route. I took a look in Laravel, it has a domain function, is it suitable to use in my case? I think I can build route for comment.shop.mycompany.com, not sure about building shop.mycompany.com route.

Thank you for your time, please let me know if I miss any information to make the decision.

CodePudding user response:

No, you don‘t need an entirely new Laravel application. Laravel can route on whatever routes you give it:

Route::domain('comment.example.com')->group(function () {
    // Comment routes here
});

Route::domain('{shop}.example.com')->group(function () {
    // Shop routes here
});

CodePudding user response:

I all depends how your hosting is set up.

if you do not have a subdomain pointed to a different folder you can basically use *.yourdomain.com

This article will may help you further. https://www.freecodecamp.org/news/laravel-subdomians/

CodePudding user response:

Route::domain('shop.' . env('DOMAIN_NAME'))->group(function () {
    // Shop related api goes here
});

Route::domain('comment.' . env('DOMAIN_NAME'))->group(function () {
    // Comment related api goes here
});

Subject to your main Domain URL is defined as in .env file

APP_URL="https://${DOMAIN_NAME}" // This one is neccessary for your app to work for static assets and non domain URLs
DOMAIN_NAME=mycompany.com
  • Related