我的 Laravel 应用程序中有多个 MySQL 连接到不同的数据库。我知道我不能用 覆盖默认连接DB::connection,但我想知道是否有办法在函数的给定范围内只覆盖一次。
例如我目前:
DB::connection('mysql2')->table('users')->select ...
DB::connection('mysql2')->table('orders')->insert ...
...
...
但我希望:
DB::connection('mysql2'); // override connection once in this scope
DB::table('users')->select ...
DB::table('orders')->insert ...
慕工程0101907
慕侠2389804
随时随地看视频慕课网APP