getOwnerRecord(); return $table ->columns([ TextColumn::make('version')->label('Fassung')->prefix('Nr. '), TextColumn::make('published_at')->label('Veröffentlicht')->dateTime('d.m.Y H:i'), TextColumn::make('published_by')->label('Von')->state(fn (InquiryTemplateVersion $record): string => (string) User::query()->whereKey($record->published_by)->value('name')), TextColumn::make('note')->label('Bemerkung')->placeholder('–'), TextColumn::make('state')->label('Zustand')->badge() ->color(fn (string $state): string => $state === 'Gültig' ? 'success' : 'gray') ->state(fn (InquiryTemplateVersion $record): string => $record->id === $this->getOwnerRecord()->published_version_id ? 'Gültig' : 'Früher'), TextColumn::make('inquiries')->label('Anfragen')->state(fn (InquiryTemplateVersion $record): int => Inquiry::query()->where('template_version_id', $record->id)->count()), ]) ->recordActions([ Action::make('restore') ->label('Wieder in Kraft setzen') ->visible(fn (InquiryTemplateVersion $record): bool => $record->id !== $template->fresh()->published_version_id) ->requiresConfirmation() ->modalDescription('Besucher sehen danach wieder diese Fassung. Der Entwurf bleibt unverändert. Eingegangene Anfragen bleiben ihrer damaligen Fassung zugeordnet.') ->action(function (InquiryTemplateVersion $record): void { try { app(Publisher::class)->restoreVersion($this->getOwnerRecord(), $record); } catch (ValidationException $e) { Notification::make()->title('Nicht möglich')->body(implode(' ', $e->errors()['draft'] ?? []))->danger()->send(); return; } Notification::make()->title('Fassung '.$record->version.' ist wieder gültig.')->success()->send(); $this->redirect(InquiryTemplateResource::getUrl('edit', ['record' => $this->getOwnerRecord()])); }), Action::make('load') ->label('Als Entwurf laden') ->color('gray') ->requiresConfirmation() ->modalDescription('Der aktuelle Entwurf wird durch den Stand dieser Fassung ersetzt. Veröffentlicht wird dadurch nichts.') ->action(function (InquiryTemplateVersion $record): void { $this->getOwnerRecord()->forceFill(['draft' => $record->source])->save(); Notification::make()->title('Der Entwurf entspricht jetzt Fassung '.$record->version.'.')->success()->send(); $this->redirect(InquiryTemplateResource::getUrl('edit', ['record' => $this->getOwnerRecord()])); }), ]) ->defaultSort('version', 'desc') ->paginated(false); } }