Multiple database read/write connections in LaravelMarch 29, 2017
This post follows up on my previous post Multiple read-only database slaves in Laravel after I got a helpful comment from Ezequiel Russo who showed me an even better way to use multiple database read/write connections in Laravel - one that works with Laravel's config caching.
It turns out that Laravel will automatically pick a database connection at random if provided with an array, so there's no need to pick a random connection yourself. This makes it really easy to define your connections and have it work with
php artisan config:cache.
'mysql' => [ 'driver' => 'mysql', 'read' => [ 'host' => ['22.214.171.124', '126.96.36.199'] ], 'write' => [ 'host' => '188.8.131.52' ], // ]
A blog about Laravel & Rails, written by Dwight Watson.