You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found that querying models on seeders are using using default root tenant so behaviour is unexpected.
$tenants = app('rinvex.tenants.tenant')->all();
foreach ($tenants as $tenant) {
$all_users = User::withAllTenants($tenant)->get(); <-- Not working, gets main domain users
$all_users = User::withAnyTenants($tenant)->get(); <-- Not working, gets main domain users
$all_users = $tenant->entries(User::class)->get(); <-- Not working, gets main domain users
}
I finally made my own trait that works thanks to "withoutGlobalScopes":
trait ForTenant
{
public function scopeForTenant($builder, $tenant)
{
return (new static())->newQuery()->withoutGlobalScopes(['tenantable'])->whereHas('tenants', function ($builder) use ($tenant) {
$builder->where($key = $tenant->getKeyName(), $tenant->{$key})->where('is_active', true);
});
}
}
Could there be a better solution for this?
A)
withAnyTenantsWithoutGlobalScopes methods?
B)
initialize withAnyTenant methods with withoutGlobalScopes when application running outside request cycle?
C)
I still find strange I am the first to deal with this issue and there must be something wrong with my setup...
3 tenants with 3 subdomains created with a seeder:
I've found that querying models on seeders are using using default root tenant so behaviour is unexpected.
I finally made my own trait that works thanks to "withoutGlobalScopes":
Could there be a better solution for this?
A)
withAnyTenantsWithoutGlobalScopes methods?
B)
initialize withAnyTenant methods with withoutGlobalScopes when application running outside request cycle?
C)
I still find strange I am the first to deal with this issue and there must be something wrong with my setup...
3 tenants with 3 subdomains created with a seeder:
Config/app.php entry:
and at .env file:
MULTITENANT_DOMAIN=domain.org
The text was updated successfully, but these errors were encountered: