mehmood
mehmood

Reputation: 301

How do you separate backend and frontend in laravel projects?

I'm new to Laravel.

I'm working on a project which involves a public facing website and back-office application. Both are web applications and suppose to be hosted on different domains.

The reason for keeping these two apps separately is so that on the public facing website we don't push unnecessary code and keep it lean and clean. However, both of them are using the same database so I want to create a module/app/plugin (Not sure how to name it in Laravel) which can be shared among both applications for database models or any other business logic which can be shared between both apps.

Any idea how to achieve that with laravel framework?

Upvotes: 4

Views: 3832

Answers (1)

Antoine Bellion
Antoine Bellion

Reputation: 136

Based on my experience, the most obvious approach would be to have one backend (API) used by the two frontends.

  • API : Exposing REST endpoints, configured with proper authorizations (some endpoints would only be for admins users).
  • Website : A classic website (SPA or not) interacting with the business logic through the API.
  • Back-Office : Same story as the website.

It's somehow a microservice architecture. There is a lot of pros and cons for it, but considering you don't want to push unnecessary code, spreading into different apps seems like appropriate.

If you want to keep one code base, I would consider having a load balancer (like HaProxy or Nginx) in front of your Laravel app to handle requests from configured domains to appropriate routes. For example :

  • acme.com root would be / for Laravel
  • bo.acme.com root would be /admin for Laravel

Upvotes: 2

Related Questions