简体   繁体   中英

Managing multiple sites with a single Laravel installation

Is it possible to have multiple sites inside of a single Laravel instance? For example, can I have the front-end code for two sites live inside of the same Laravel installation.

The reason is, I am creating a single API that will be used by many of my sites, and all the sites will share the same data but branding (and some pages) will be different. An I want to take advantage of using PHP on the sites along with the API.

Would this be a possible solution, or would I have to create separate sites outside of Laravel that just call the API I have created.

Is this the best solution for what I want to achieve?

Thanks you.

Deciding what is best is very subjective, so it's hard to say.

There is an argument for having separate projects, in order to maintain separation of concerns. While it seems counter productive, it might help you maintain order between the different parts of the project and allow the codebase to be more minimal.

Having it in one, you could consider using a routing for a subdomain. For example, Sub-Domain Routing :

Route::domain('api.myapp.com')->group(function () {
    Route::get('v1/post/{id}', function ($id) {
        //
    });
});

I don't think there's a right answer, it depends on what your priorities are. I would say using a rule of three, if you're intending to make more sites that use the API, then the API should be in a separate project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM