mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 12:44:04 +00:00
add Tenancy::$findWith
This commit is contained in:
parent
5ef7604e17
commit
ac5948dfd1
5 changed files with 24 additions and 13 deletions
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue