简体   繁体   English

Laravel 多租户查询生成器使用错误的数据库

[英]Laravel Multi Tenancy Query Builder use wrong database

I use spatie laravel multi tenancy.我使用 spatie laravel 多租户。

https://spatie.be/docs/laravel-multitenancy/v1/installation/using-multiple-databases https://spatie.be/docs/laravel-multitenancy/v1/installation/using-multiple-databases

I want to do a simple query with query builder.我想用查询生成器做一个简单的查询。

DB:table('users')->select('username')->get(); // i would like use this

But use wrong database homestead .但是使用了错误的数据库homestead If I use the model it works fine.如果我使用 model 它工作正常。

User::select('username')->get();

How can I solve this problem?我怎么解决这个问题?

using the DB Facade you should specify the connection name like so:使用 DB Facade,您应该像这样指定连接名称:

DB::connection('tenant')->table('users')->....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM