Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
Show First 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | public function domain() | ||||
$domain = \App\Domain::withTrashed()->where('namespace', $domainName)->first(); | $domain = \App\Domain::withTrashed()->where('namespace', $domainName)->first(); | ||||
return $domain; | return $domain; | ||||
} | } | ||||
/** | /** | ||||
* List the domains to which this user is entitled. | * List the domains to which this user is entitled. | ||||
* Note: Active public domains are also returned (for the user tenant). | |||||
* | * | ||||
* @return Domain[] | * @return Domain[] List of Domain objects | ||||
*/ | */ | ||||
public function domains() | public function domains(): array | ||||
{ | { | ||||
$domains = Domain::whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC)) | if ($this->tenant_id) { | ||||
$domains = Domain::where('tenant_id', $this->tenant_id); | |||||
} else { | |||||
$domains = Domain::withEnvTenant(); | |||||
} | |||||
$domains = $domains->whereRaw(sprintf('(type & %s)', Domain::TYPE_PUBLIC)) | |||||
->whereRaw(sprintf('(status & %s)', Domain::STATUS_ACTIVE)) | ->whereRaw(sprintf('(status & %s)', Domain::STATUS_ACTIVE)) | ||||
->get() | ->get() | ||||
->all(); | ->all(); | ||||
foreach ($this->wallets as $wallet) { | foreach ($this->wallets as $wallet) { | ||||
$entitlements = $wallet->entitlements()->where('entitleable_type', Domain::class)->get(); | $entitlements = $wallet->entitlements()->where('entitleable_type', Domain::class)->get(); | ||||
foreach ($entitlements as $entitlement) { | foreach ($entitlements as $entitlement) { | ||||
$domains[] = $entitlement->entitleable; | $domains[] = $entitlement->entitleable; | ||||
▲ Show 20 Lines • Show All 432 Lines • Show Last 20 Lines |