*/ public array $data = []; public function mount(string $managedTenant): void { $this->tenant = Tenant::withTrashed()->findOrFail($managedTenant); $user = auth()->user(); if (! $user instanceof User) { abort(403); } /** @var CapabilityResolver $resolver */ $resolver = app(CapabilityResolver::class); if (! $resolver->isMember($user, $this->tenant)) { abort(404); } if (! $resolver->can($user, $this->tenant, Capabilities::TENANT_MANAGED_TENANTS_MANAGE)) { abort(403); } if (! $this->tenant->isActive()) { \App\Support\ManagedTenants\ManagedTenantContext::setArchivedTenant($this->tenant); $this->redirect(ArchivedStatus::getUrl()); } $this->form->fill([ 'name' => $this->tenant->name, 'environment' => $this->tenant->environment, 'tenant_id' => $this->tenant->tenant_id, 'domain' => $this->tenant->domain, 'app_client_id' => $this->tenant->app_client_id, 'app_client_secret' => null, 'app_certificate_thumbprint' => $this->tenant->app_certificate_thumbprint, 'app_notes' => $this->tenant->app_notes, ]); } public function form(Schema $schema): Schema { return $schema ->schema([ Forms\Components\TextInput::make('name') ->required() ->maxLength(255), Forms\Components\Select::make('environment') ->options([ 'prod' => 'PROD', 'dev' => 'DEV', 'staging' => 'STAGING', 'other' => 'Other', ]) ->default('other') ->required(), Forms\Components\TextInput::make('tenant_id') ->label('Tenant ID (GUID)') ->required() ->maxLength(255), Forms\Components\TextInput::make('domain') ->label('Primary domain') ->maxLength(255), Forms\Components\TextInput::make('app_client_id') ->label('App Client ID') ->maxLength(255), Forms\Components\TextInput::make('app_client_secret') ->label('App Client Secret') ->password() ->dehydrateStateUsing(fn ($state) => filled($state) ? $state : null) ->dehydrated(fn ($state) => filled($state)), Forms\Components\TextInput::make('app_certificate_thumbprint') ->label('Certificate thumbprint') ->maxLength(255), Forms\Components\Textarea::make('app_notes') ->label('Notes') ->rows(3), ]) ->statePath('data'); } public function save(): void { $user = auth()->user(); if (! $user instanceof User) { abort(403); } /** @var CapabilityResolver $resolver */ $resolver = app(CapabilityResolver::class); if (! $resolver->can($user, $this->tenant, Capabilities::TENANT_MANAGED_TENANTS_MANAGE)) { abort(403); } $data = $this->form->getState(); $this->tenant->fill($data); $this->tenant->save(); Notification::make() ->title('Managed tenant updated') ->success() ->send(); $this->redirect(ViewManagedTenant::getUrl(['tenant' => $this->tenant])); } }