Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you separate backend and frontend in laravel projects?

Tags:

php

laravel

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.

  • Website - the Public facing website using the database to pull data.
  • Back-Office - Backoffice or Admin app to create/update/delete stuff again using the same database should have it's own RBAC.

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?

like image 730
mehmood Avatar asked Oct 18 '25 16:10

mehmood


1 Answers

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
like image 151
Antoine Bellion Avatar answered Oct 20 '25 06:10

Antoine Bellion