我在两个不同的数据库中有两组用户。但是如何检查两个database.users表?我在想这样的事情吗?
$user = new User;
$user->setTable('other-database.users');
// or
$user->setConnection('other-database');
if (\Auth::attempt(['email' => $email, 'password' => $password])) {
// Authentication passed...
return redirect()->intended('dashboard');
} else {
dd('nope');
}
答案 0 :(得分:0)
如果您有来自不同连接的多个模型,则可以通过添加$connection
属性来指定要在模型上使用的连接。
protected $connection = 'connection-name';
使用查询构建器,您可以设置要在运行中使用的连接。
$users = DB::connection('connection-name')->select(...);
你可以用雄辩的方式做到这一点。
$user = User::on(‘connection-name’)->find(1);