在此位置:.. \ config \ database.php
'mysql' => [
'read' => [
'host' => env('DB_HOST_READ', '127.0.0.2'),
],
'write' => [
'host' => env('DB_HOST_WRITE', '127.0.0.1'),
],
'driver' => 'mysql',
// 'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
.env文件已添加:
DB_HOST_READ=127.0.0.2
DB_HOST_WRITE=127.0.0.1
查看读取和写入主机值。我想验证用于读取和写入查询的当前运行查询的主机。
我正在使用Laravel 5.5。那么我怎样才能获得每个查询的DB_HOST值?
答案 0 :(得分:1)
env('DB_HOST_READ');
env('DB_HOST_WRITE');