mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 14:14:04 +00:00
path identification wip
This commit is contained in:
parent
7ad93adde5
commit
5e6d82be57
8 changed files with 215 additions and 3 deletions
|
|
@ -4,14 +4,13 @@ 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();
|
||||
$domain = config('tenancy.domain_model')::where('domain', $args[0])->first();
|
||||
|
||||
if ($domain) {
|
||||
return $domain->tenant;
|
||||
|
|
|
|||
27
src/Resolvers/PathTenantResolver.php
Normal file
27
src/Resolvers/PathTenantResolver.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Resolvers;
|
||||
|
||||
use Illuminate\Routing\Route;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Stancl\Tenancy\Contracts\TenantResolver;
|
||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByPathException;
|
||||
|
||||
class PathTenantResolver implements TenantResolver
|
||||
{
|
||||
public function resolve(...$args): Tenant
|
||||
{
|
||||
/** @var Route $route */
|
||||
$route = $args[0];
|
||||
|
||||
if ($id = $route->parameter('tenant')) {
|
||||
$route->forgetParameter('tenant');
|
||||
|
||||
if ($tenant = config('tenancy.tenant_model')::find($id)) {
|
||||
return $tenant;
|
||||
}
|
||||
}
|
||||
|
||||
throw new TenantCouldNotBeIdentifiedByPathException($id);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue