'required|string|max:255', 'type' => 'array|exclude', ]; } public function validationAttributes(): array { return [ 'typeClass' => 'Typ', 'name' => 'Bezeichnung', ]; } public function mount(?string $id = null): void { $this->types = ConnectionType::forSelect(); if ($id) { $this->model = Fileshare::findOrFail($id); $this->name = $this->model->name; $this->typeClass = get_class($this->model->type); $this->type = $this->model->type->toArray(); } } public function fields(): array { return $this->typeClass ? $this->typeClass::fields() : []; } public function updatedTypeClass(?string $type): void { if (!$type) { return; } $this->type = $type::defaults(); } #[On('onStoreFromModal')] public function onSave(): void { $payload = $this->validate(); $type = $this->typeClass::from($this->type); if (!$type->check()) { throw ValidationException::withMessages(['typeClass' => 'Verbindung fehlgeschlagen']); } if ($this->model) { $this->model->update([...$payload, 'type' => $type]); } else { Fileshare::create([ ...$payload, 'type' => $type, ]); } $this->dispatch('closeModal'); $this->dispatch('refresh-page'); $this->dispatch('success', $this->model ? 'Verbindung aktualisiert.' : 'Verbindung erstellt.'); } public function render() { return <<<'HTML'
@foreach($this->fields() as $index => $field) @endforeach
HTML; } }