hasRole('super-admin'); } public function mount(): void { $cfg = FeCassettoServiceConfig::query()->first(); $this->getSchema('form')?->fill([ 'base_url' => (string) ($cfg?->base_url ?? ''), // secrets intentionally not prefilled 'password_script' => null, 'username' => null, 'password' => null, 'pin' => null, ]); } public function form(Schema $schema): Schema { return $schema ->statePath('data') ->components([ Section::make('Parametri servizio (globali)') ->columns(2) ->schema([ TextInput::make('base_url') ->label('URL base (opzionale)') ->helperText('Se vuoto, usa il default di sistema.') ->maxLength(512) ->columnSpanFull(), TextInput::make('password_script') ->label('passwordScript (licenza)') ->password() ->revealable() ->helperText('Lascia vuoto per non modificare.') ->dehydrated(fn ($state): bool => filled($state)) ->maxLength(255) ->columnSpanFull(), TextInput::make('username') ->label('Username Entratel') ->helperText('Lascia vuoto per non modificare.') ->dehydrated(fn ($state): bool => filled($state)) ->maxLength(255), TextInput::make('password') ->label('Password Entratel') ->password() ->revealable() ->helperText('Lascia vuoto per non modificare.') ->dehydrated(fn ($state): bool => filled($state)) ->maxLength(255), TextInput::make('pin') ->label('PIN Entratel') ->password() ->revealable() ->helperText('Lascia vuoto per non modificare.') ->dehydrated(fn ($state): bool => filled($state)) ->maxLength(255), ]), ]); } public function submit(): void { $state = $this->getSchema('form')?->getState() ?? []; if (is_array($state['data'] ?? null)) { $state = $state['data']; } elseif (is_array($this->data ?? null) && ! empty($this->data)) { $state = $this->data; } /** @var FeCassettoServiceConfig $cfg */ $cfg = FeCassettoServiceConfig::query()->firstOrCreate(['id' => 1], []); $update = [ 'base_url' => trim((string) ($state['base_url'] ?? '')) ?: null, ]; foreach (['password_script', 'username', 'password', 'pin'] as $k) { if (isset($state[$k]) && filled($state[$k])) { $update[$k] = (string) $state[$k]; } } $cfg->fill($update); $cfg->save(); Notification::make() ->title('Configurazione salvata') ->success() ->send(); // Clear secrets from local form state $this->getSchema('form')?->fill([ 'base_url' => (string) ($cfg->base_url ?? ''), 'password_script' => null, 'username' => null, 'password' => null, 'pin' => null, ]); } }