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

amitsolanki24_'s avatar

Use laravel modules for different domains

https://github.com/nWidart/laravel-modules

Can I use laravel modules approach to maintain multiple project in a single codebase because they uses mostly same code I want to manage them from a single codebase.

All projects have different domain so after implementing laravel modules approach how can I use one module for one domain and other domains for other modules.

0 likes
7 replies
JussiMannisto's avatar

Modules are not for serving multiple apps. They're for separating different parts of a single app. That is, if you want to structure your (large) app like that.

Combining unrelated apps under a single project just to reuse code is a bad idea. You can create packages for that. Then you can develop and host the apps separately.

1 like
JussiMannisto's avatar

@amitsolanki24_ Do what? Reuse code? Well there's always copy-paste, if you don't know how to create packages.

If the websites are simply white labels of the same site, and you think it's a good idea to run them from a single Laravel instance, then you can do it. There are many ways to do it. You might create a service provider that detects the requested domain and injects site-specific settings to the app container. Or you might define domain-specific routes. In any case, it's going to be more complicated than running each site separately.

But don't try to run completely separate apps together just to avoid rewriting code.

1 like
martinbean's avatar

@amitsolanki24_ When people talk about separate code by domain they mean “domain” as in business domain and not domain as in web addresses.

Tray2's avatar

@amitsolanki24_ What @martinbean is trying to say (I think), is that when developers talk about domains they mean business domains, for example Products might be one of those business domains, and Customers another, and instead of using the regular Larvel MVC you put all the things related to products, in a products domain (directory), all the controllers, views, models, and any other classes related to the products domain, the same goes for customers. It's a way of separating the code base into their own little MVC system, and each of these are considered as a domain.

What you are attempting to do (I think) is to reuse the logic of your application, but change the presentation layer between different sites.

I would not create views that contains logic to determine what should be displayed depending on which site it is, it will be hell to maintain when you add more sites. I would most likely either build a separate frontend for each and use Laravel for the backend, or like @jussimannisto suggested, use the base functionality from you backend, and build packages for the frontend (read views), for each site, that you can pull in with a simple composer command.

1 like

Please or to participate in this conversation.