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' => ['126.96.36.199', '188.8.131.52'] ], 'write' => [ 'host' => '184.108.40.206' ], // ]