1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 14:14:04 +00:00

add Tenancy::$findWith

This commit is contained in:
Samuel Štancl 2024-04-05 19:48:50 +02:00
parent 5ef7604e17
commit ac5948dfd1
5 changed files with 24 additions and 13 deletions

View file

@ -10,6 +10,7 @@ use Stancl\Tenancy\Contracts\Domain;
use Stancl\Tenancy\Contracts\SingleDomainTenant;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException;
use Stancl\Tenancy\Tenancy;
class DomainTenantResolver extends Contracts\CachedTenantResolver
{
@ -21,15 +22,16 @@ class DomainTenantResolver extends Contracts\CachedTenantResolver
$domain = $args[0];
/** @var Tenant&Model $tenantModel */
$tenantModel = config('tenancy.models.tenant')::make();
$tenantModel = tenancy()->model();
if ($tenantModel instanceof SingleDomainTenant) {
$tenant = $tenantModel->newQuery()
->with(Tenancy::$findWith)
->firstWhere('domain', $domain);
} else {
$tenant = $tenantModel->newQuery()
->whereHas('domains', fn (Builder $query) => $query->where('domain', $domain))
->with('domains')
->with(array_unique(array_merge(Tenancy::$findWith, ['domains'])))
->first();
}

View file

@ -26,7 +26,7 @@ class PathTenantResolver extends Contracts\CachedTenantResolver
}
if ($key) {
if ($tenant = tenancy()->find($key, $column)) {
if ($tenant = tenancy()->find($key, $column, withRelations: true)) {
/** @var Tenant $tenant */
return $tenant;
}

View file

@ -20,7 +20,7 @@ class RequestDataTenantResolver extends Contracts\CachedTenantResolver
{
$payload = (string) $args[0];
if ($payload && $tenant = tenancy()->find($payload)) {
if ($payload && $tenant = tenancy()->find($payload, withRelations: true)) {
return $tenant;
}