This is recommended regulation for database divide setting in Laravel.
'mysql' => [
'read' => [
'host' => '192.168.1.1',
],
'write' => [
'host' => '196.168.1.2'
],
'sticky' => true,
'driver' => 'mysql',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
],
But if I want to use different access information as DB_NAME, USER_ID, PASS etc to each read/write databases, then how could I make it? Thank you.
You can create two connections then specify the connection with Eloquent using the on method:
Or using Query Builder: