tenancy / multi-tenant

Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant
https://tenancy.dev
MIT License
2.56k stars 394 forks source link

change tenant connection to system #924

Closed rawdasherif119 closed 4 years ago

rawdasherif119 commented 4 years ago

i need to get data from one tenant so i set connection using app(Environment::class)->tenant($website);

now i need to set this data to system database but using DB::connection('system') not good for me because i need to use eloquent relation to insert this data i need to set system connection globally again in the same method anyway?

bkintanar commented 4 years ago

You can use Model::on('system')

rawdasherif119 commented 4 years ago

You can use Model::on('system')

still insert into tenant database because i am using UseTenantConnection in model ??

fletch3555 commented 4 years ago

I don't quite understand why you're doing that @Dev12230. A model class should use the UsesSystemConnection or UsesTenantConnection trait. The system connection is ALWAYS available, and the tenant connection is only available if a tenant has been identified.

This means that the two connections exist in parallel and you should have no problem using the system connection at any point assuming your models are configured correctly.

bkintanar commented 4 years ago

Closing this issue. If you are still having issues with the package, please create a new issue. Thank you