Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/panels/src/Http/Middleware/IdentifyTenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function handle(Request $request, Closure $next): mixed
abort(404);
}

$tenant = $panel->getTenant($request->route()->parameter('tenant'));
$tenant = $panel->resolveTenantForRequest($request->route()->parameter('tenant'));

if (! $user->canAccessTenant($tenant)) {
abort(404);
Expand Down
20 changes: 20 additions & 0 deletions packages/panels/src/Panel/Concerns/HasTenancy.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ trait HasTenancy

protected ?string $tenantOwnershipRelationshipName = null;

protected ?Closure $tenantIdentifier = null;

/**
* @var array<Action | Closure | MenuItem>
*/
Expand Down Expand Up @@ -137,6 +139,13 @@ public function tenantRegistration(?string $page): static
return $this;
}

public function identifyTenant(?Closure $callback): static
{
$this->tenantIdentifier = $callback;

return $this;
}

public function hasTenancy(): bool
{
return filled($this->getTenantModel());
Expand Down Expand Up @@ -202,6 +211,17 @@ public function getTenantRegistrationPage(): ?string
return $this->tenantRegistrationPage;
}

public function resolveTenantForRequest(string $key): Model
{
if ($this->tenantIdentifier) {
return $this->evaluate($this->tenantIdentifier, [
'key' => $key,
]);
}

return $this->getTenant($key);
}

public function getTenant(string $key): Model
{
$tenantModel = $this->getTenantModel();
Expand Down