Laravel multitenancy with a user-only BD

Asked

Viewed 462 times

5

I’ve been researching about Saas and Multi-tenancy but has little material in Portuguese. I saw that it is possible to make a database for each company, but my question is:

You can make a unique web system for all clients (using PHP+Laravel+Mysql) with a Banco de dados for each company BUT make a Banco de dados only of "empresas"(containing a table "users" with the fields of empresa, usuário, senha, and bd_empresa) using this comic book of empresa only to check the login and if the data is right log into the application using that company’s BD?

I don’t know if I could make it clear, I hope so.

  • Your question seems quite clear, but also very broad. I don’t know how far the community can actually help in this case. I generally believe that your proposal is feasible. In practice there may be some challenges (I think more conceptual than technical) that should be addressed specifically and individually.

  • It gives yes, I do not use and I do not have knowledge in PHP frameworks, I do everything in the nail, in PDO, but in my system it is basically like this, each company has a specific database, and they share a common database, in the specific database, contains the tables of each one, and in the common bank contain information of public access and exclusive of the system, both for login, and for exactly the same way to search the bank of each one. The moment the company executes the login, it searches for its BD, and this information is passed to the constructor method of the class

2 answers

0

I have two Saas systems developed in Laravel, and use a single database.

For the separation of data by company, all tables have the foreign key referencing the contractor table.

To help the code, actually in a very transparent way, I use this package that uses traits to always filter by the company that the authenticated user belongs to:

https://github.com/torzer/awesome-landlord

There are other alternatives that work with the solution of multiple databases, one per tenant, and also that allow segregate and manage tenants by subdomain, the most robust that I have analyzed to use these approaches, in relation to stability and continuous development are:

0

It has a way of doing yes and has several approaches.

1 - Use multi-tenant library

https://github.com/hyn/multi-tenant

2 - Make a class that will serve as middleware and always make the requisitions in the bank of the correct company.

3 - Distribute the application and leave a service responsible for managing the databases and their queries

Either way goes a lot of what you need to do

Browser other questions tagged

You are not signed in. Login or sign up in order to post.