Neun weitere Standard-Header (md) auf <x-portal.page-header>: - roles/index (bedingter Anlegen-Button), roles/create (Guard-Badge via :meta), roles/edit (ID + Guard + bedingte Systemrolle via :meta) - footer-codes/index, footer-codes/create, footer-codes/edit (ID + Global + Aktiv/Inaktiv via :meta, Titel als Beschreibung) - presets/index, presets/create, presets/edit (ID via :meta) Roles-/FooterCode-/Preset-Tests (23) gruen. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
104 lines
3.4 KiB
PHP
104 lines
3.4 KiB
PHP
<?php
|
|
|
|
use App\Models\AdminPreset;
|
|
use Illuminate\Validation\Rule;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Volt\Component;
|
|
|
|
new #[Layout('components.layouts.app'), Title('Voreinstellung bearbeiten')] class extends Component
|
|
{
|
|
#[Locked]
|
|
public int $id;
|
|
|
|
public string $key = '';
|
|
|
|
public string $area = '';
|
|
|
|
public string $type = 'text';
|
|
|
|
public string $label = '';
|
|
|
|
public string $value = '';
|
|
|
|
public string $payload = '';
|
|
|
|
public bool $isActive = true;
|
|
|
|
public function mount(int $id): void
|
|
{
|
|
$this->id = $id;
|
|
|
|
$preset = AdminPreset::query()->findOrFail($id);
|
|
|
|
$this->key = $preset->key;
|
|
$this->area = $preset->area;
|
|
$this->type = $preset->type;
|
|
$this->label = $preset->label;
|
|
$this->value = $preset->value ?? '';
|
|
$this->payload = $preset->payload ? json_encode($preset->payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) : '';
|
|
$this->isActive = $preset->is_active;
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$validated = $this->validate([
|
|
'key' => ['required', 'string', 'max:255', 'regex:/^[a-z0-9_.-]+$/', Rule::unique('admin_presets', 'key')->ignore($this->id)],
|
|
'area' => ['required', 'string', 'max:100'],
|
|
'type' => ['required', Rule::in(['text', 'number', 'boolean', 'json'])],
|
|
'label' => ['required', 'string', 'max:255'],
|
|
'value' => ['nullable', 'string'],
|
|
'payload' => ['nullable', 'json'],
|
|
'isActive' => ['boolean'],
|
|
]);
|
|
|
|
AdminPreset::query()
|
|
->findOrFail($this->id)
|
|
->update([
|
|
'key' => $validated['key'],
|
|
'area' => $validated['area'],
|
|
'type' => $validated['type'],
|
|
'label' => $validated['label'],
|
|
'value' => $validated['value'] ?: null,
|
|
'payload' => filled($validated['payload']) ? json_decode($validated['payload'], true) : null,
|
|
'is_active' => $validated['isActive'],
|
|
]);
|
|
|
|
session()->flash('success', __('Voreinstellung wurde gespeichert.'));
|
|
|
|
$this->redirect(route('admin.presets.index'), navigate: true);
|
|
}
|
|
}; ?>
|
|
|
|
<form wire:submit="save" class="space-y-8">
|
|
{{-- ============== PAGE HEADER ============== --}}
|
|
<x-portal.page-header
|
|
:badge="__('Admin Backend')"
|
|
:eyebrow="__('Administration · Voreinstellungen')"
|
|
:title="__('Voreinstellung bearbeiten')"
|
|
:description="__('Texte, Zahlen oder JSON-Werte zentral fuer Admin-Funktionen pflegen.')"
|
|
>
|
|
<x-slot:meta>
|
|
<span class="badge hub">ID #{{ $id }}</span>
|
|
</x-slot:meta>
|
|
<x-slot:actions>
|
|
<flux:button variant="filled" icon="arrow-left" href="{{ route('admin.presets.index') }}" wire:navigate>
|
|
{{ __('Zurück') }}
|
|
</flux:button>
|
|
</x-slot:actions>
|
|
</x-portal.page-header>
|
|
|
|
@include('livewire.admin.presets.partials.form-fields')
|
|
|
|
<article class="panel">
|
|
<div class="p-5 flex justify-end gap-3">
|
|
<flux:button variant="filled" href="{{ route('admin.presets.index') }}" wire:navigate>
|
|
{{ __('Abbrechen') }}
|
|
</flux:button>
|
|
<flux:button type="submit" variant="primary">
|
|
{{ __('Änderungen speichern') }}
|
|
</flux:button>
|
|
</div>
|
|
</article>
|
|
</form>
|