D
D
Dmitry Kuznetsov2018-11-04 11:34:49
MySQL
Dmitry Kuznetsov, 2018-11-04 11:34:49

Multiple databases in one Laravel application?

Hello. When developing the project, I ran into one problem:
There is 1 site, in which we must receive both data from the site database and from other databases. Is it possible to implement this using Laravel without dancing with a tambourine? The databases are on different servers.
The docs only describe how to make read / write requests, although I don’t understand something like that.
Just in case, I will prescribe the algorithm for obtaining data:
1. We go to the user profile on the site
2. First, we get data from the site database about the user
3. When choosing additional. settings (drop-down list), we get other data from another database.
4. We display all this on the page.
There is one more option how to implement it, but in my opinion it's a bicycle - several laravel api applications that, upon request, will issue certain data from the database.
How would you solve this problem? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2018-11-04
@dima9595

Database Connection
By default, all Eloquent models will use the default database connection configured for your application. If you would like to specify a different connection for the model, use the $connection property
https://laravel.com/docs/5.7/eloquent
When using multiple connections, you may access each connection via the connection method on the DB facade. The name passed to the connection method should correspond to one of the connections listed in your config/database.php configuration filehttps://laravel.com/docs/5.7/database#using-multip...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question