mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 15:54:03 +00:00
Domain model & resolver test
This commit is contained in:
parent
08ed5084d5
commit
e1a4054743
11 changed files with 158 additions and 8 deletions
22
src/Resolvers/DomainTenantResolver.php
Normal file
22
src/Resolvers/DomainTenantResolver.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Resolvers;
|
||||
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Stancl\Tenancy\Contracts\TenantResolver;
|
||||
use Stancl\Tenancy\Database\Models\Domain;
|
||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException;
|
||||
|
||||
class DomainTenantResolver implements TenantResolver
|
||||
{
|
||||
public function resolve(...$args): Tenant
|
||||
{
|
||||
$domain = app(config('tenancy.domain_model'))->where('domain', $args[0])->first();
|
||||
|
||||
if ($domain) {
|
||||
return $domain->tenant;
|
||||
}
|
||||
|
||||
throw new TenantCouldNotBeIdentifiedOnDomainException($domain);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue