-
-
Notifications
You must be signed in to change notification settings - Fork 443
/
Copy pathDomainTenantResolver.php
51 lines (38 loc) · 1.25 KB
/
DomainTenantResolver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Resolvers;
use Stancl\Tenancy\Contracts\Domain;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException;
class DomainTenantResolver extends Contracts\CachedTenantResolver
{
/**
* The model representing the domain that the tenant was identified on.
*
* @var Domain
*/
public static $currentDomain;
/** @var bool */
public static $shouldCache = false;
/** @var int */
public static $cacheTTL = 3600; // seconds
/** @var string|null */
public static $cacheStore = null; // default
public function resolveWithoutCache(...$args): Tenant
{
/** @var Domain $domain */
$domain = config('tenancy.domain_model')::where('domain', $args[0])->first();
if ($domain) {
static::$currentDomain = $domain;
return $domain->tenant;
}
throw new TenantCouldNotBeIdentifiedOnDomainException($args[0]);
}
public function getArgsForTenant(Tenant $tenant): array
{
$tenant->unsetRelation('domains');
return $tenant->domains->map(function (Domain $domain) {
return [$domain->domain];
})->toArray();
}
}