I am creating a Laravel/latest-version application which requires several hundreds of sql table to be created to serve the job. There will again be hundreds of clients who's data will be inserted multiple times (1000 rows per client or more in some tables) in these table. To eliminate confusion, I want a general/common-database for common information and separate Database for each client for specific information and would like to create new DB when a client is added. Can this be done in Laravel (dealing with multiple Databases at once) or is there any other PHP framework which can serve this purpose better? Much obliged for your help.
1 Answers
Well most of the times, this is an architectural flaw because the db isn't designed well. Normally this kind of issue is faced due to the reason that all your tables are normalized. Normalization is good for small applications but for data rich applications you have to judge which fields need to be normalized and which doesn't need normalization. You can save lots of tables and fields with denormalization. As a rule of thumb anything that you dont have to query directly or via join can be denormalized.
Anyways it is possible to have multiple databases attached to a single laravel application. I have done this once on a huge application.
So the idea is that before every eloquent query you will have to set the db connection.
$someModel->setConnection('mysql2');
You can find more information about it here

- 3,754
- 6
- 31
- 60