Skip to main content

Posts

Showing posts from February 5, 2017

Multiple database connections in the same Laravel project

Sometimes there is a situation where we have our main project database, but we need to take some external data from another database – for example, where blog is stored, managed by 3rd party software. How to handle it in Laravel 5? Where to put database credentials There is a file   config/database.php   which contains an array of all possible connections- MySQL, PostgreSQL, SQL Server. So the “trick” here is we can add more than one connection with the same database system, let’s say it will be MySQL. So, let’s copy a default array item and paste as another one underneath – and call it   mysql_external : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33     'connections' => [           'sqlite' => [            ...