我的网络应用程序连接了多个数据库。
这些是:write
和read
我有一个 Eloquent 数据库查询:
$users = User::whereIsAdmin(0)->get();
我希望此数据库查询使用 read
数据库,因为默认情况下我的应用程序正在读取 write
数据库。
我该怎么做?
谢谢!
最佳答案
我查看了 Laravel Eloquent Models 的源代码,这里:
https://github.com/laravel/framework/blob/5.4/src/Illuminate/Database/Eloquent/Model.php#L303
它说应该使用 on
来更改连接。
所以:
User::on("read")->whereIsAdmin(0)->get();
关于Laravel Eloquent 多数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43183513/