43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Concerns;
|
|
|
|
use App\Models\Tenant;
|
|
use App\Support\OperateHub\OperateHubShell;
|
|
use Filament\Facades\Filament;
|
|
use RuntimeException;
|
|
|
|
trait ResolvesPanelTenantContext
|
|
{
|
|
protected static function resolveTenantContextForCurrentPanel(): ?Tenant
|
|
{
|
|
if (Filament::getCurrentPanel()?->getId() === 'admin') {
|
|
$tenant = app(OperateHubShell::class)->tenantOwnedPanelContext(request());
|
|
|
|
return $tenant instanceof Tenant ? $tenant : null;
|
|
}
|
|
|
|
$tenant = Tenant::current();
|
|
|
|
return $tenant instanceof Tenant ? $tenant : null;
|
|
}
|
|
|
|
public static function panelTenantContext(): ?Tenant
|
|
{
|
|
return static::resolveTenantContextForCurrentPanel();
|
|
}
|
|
|
|
protected static function resolveTenantContextForCurrentPanelOrFail(): Tenant
|
|
{
|
|
$tenant = static::resolveTenantContextForCurrentPanel();
|
|
|
|
if (! $tenant instanceof Tenant) {
|
|
throw new RuntimeException('No tenant context selected.');
|
|
}
|
|
|
|
return $tenant;
|
|
}
|
|
}
|