'', 'showForm' => false, 'editingId' => null, 'editLocale' => 'de', 'referenceTitle' => '', 'description' => '', 'location' => '', 'year' => '', 'image' => '', 'gallery' => [], 'brandSlugs' => [], 'is_published' => true, 'order' => 0, ]); on(['media-selected' => function ($mediaId, $url, $field) { $media = $mediaId ? CmsMedia::find($mediaId) : null; if (! $media) { return; } if ($field === 'reference_image') { $this->image = $media->filename; } if (str_starts_with($field, 'reference_gallery:')) { $index = (int) substr($field, strlen('reference_gallery:')); if (isset($this->gallery[$index])) { $this->gallery[$index]['image'] = $media->filename; } } }]); $references = computed( fn () => CmsReference::query() ->when($this->search, fn ($q, $s) => $q->where('location', 'like', "%{$s}%") ->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(title, '$.de')) LIKE ?", ["%{$s}%"])) ->ordered() ->get(), ); $brands = computed(fn () => CmsBrand::query()->ordered()->get()); $openCreate = function () { $this->editingId = null; $this->reset(['referenceTitle', 'description', 'location', 'year', 'image']); $this->gallery = []; $this->brandSlugs = []; $this->is_published = true; $this->order = (CmsReference::max('order') ?? 0) + 1; $this->showForm = true; }; $loadLocaleFields = function (CmsReference $reference, string $locale) { $this->referenceTitle = $reference->getTranslation('title', $locale) ?? ''; $this->description = $reference->getTranslation('description', $locale) ?? ''; }; $openEdit = function (int $id) { $reference = CmsReference::find($id); if (! $reference) { return; } $this->editingId = $id; $this->location = $reference->location ?? ''; $this->year = $reference->year ?? ''; $this->image = $reference->image ?? ''; $this->gallery = CmsReference::normalizeGallery($reference->gallery); $this->brandSlugs = array_values(array_map('strval', $reference->brand_slugs ?? [])); $this->is_published = $reference->is_published; $this->order = $reference->order ?? 0; $this->loadLocaleFields($reference, $this->editLocale); $this->showForm = true; }; $switchLocale = function (string $locale) { $this->editLocale = $locale; if ($this->editingId) { $reference = CmsReference::find($this->editingId); if ($reference) { $this->loadLocaleFields($reference, $locale); } } }; $addGalleryImage = fn () => $this->gallery[] = ['image' => '', 'caption' => '']; $removeGalleryImage = function (int $index) { unset($this->gallery[$index]); $this->gallery = array_values($this->gallery); }; $moveGalleryImage = function (int $index, int $direction) { $target = $index + $direction; if (! isset($this->gallery[$index], $this->gallery[$target])) { return; } [$this->gallery[$index], $this->gallery[$target]] = [$this->gallery[$target], $this->gallery[$index]]; }; $save = function () { $validated = validator([ 'referenceTitle' => $this->referenceTitle, 'description' => $this->description, 'location' => $this->location, 'year' => $this->year, 'image' => $this->image, 'brandSlugs' => $this->brandSlugs, 'is_published' => $this->is_published, 'order' => $this->order, ], [ 'referenceTitle' => 'required|string|max:255', 'description' => 'nullable|string|max:4000', 'location' => 'nullable|string|max:255', 'year' => 'nullable|string|max:20', 'image' => 'nullable|string|max:500', 'brandSlugs' => 'array', 'brandSlugs.*' => 'string|exists:cms_brands,slug', 'is_published' => 'boolean', 'order' => 'integer|min:0', ], [ 'referenceTitle.required' => 'Bitte einen Titel angeben.', 'brandSlugs.*.exists' => 'Eine der gewählten Marken gibt es nicht mehr.', ])->validate(); $reference = $this->editingId ? CmsReference::findOrFail($this->editingId) : CmsReference::query()->make(); $reference->setTranslation('title', $this->editLocale, trim($validated['referenceTitle'])); $reference->setTranslation('description', $this->editLocale, trim((string) ($validated['description'] ?? ''))); $reference->location = trim((string) ($validated['location'] ?? '')) ?: null; $reference->year = trim((string) ($validated['year'] ?? '')) ?: null; $reference->image = trim((string) ($validated['image'] ?? '')) ?: null; $reference->gallery = CmsReference::normalizeGallery($this->gallery); $reference->brand_slugs = array_values(array_unique($validated['brandSlugs'])); $reference->is_published = $validated['is_published']; $reference->order = $validated['order']; $reference->save(); $this->showForm = false; $this->editingId = null; Flux::toast(variant: 'success', heading: 'Gespeichert', text: 'Referenz wurde erfolgreich gespeichert.'); }; $togglePublished = function (int $id) { $reference = CmsReference::findOrFail($id); $reference->update(['is_published' => ! $reference->is_published]); Flux::toast(heading: 'Status geändert', text: $reference->is_published ? 'Veröffentlicht' : 'Entwurf'); }; $deleteReference = function (int $id) { CmsReference::findOrFail($id)->delete(); Flux::toast(variant: 'success', heading: 'Gelöscht', text: 'Referenz wurde entfernt.'); }; $cancelForm = function () { $this->showForm = false; $this->editingId = null; }; ?>
Noch keine weiteren Bilder.
@else{{ $reference->location ?: '–' }} · {{ $reference->year ?: '–' }} · {{ count(CmsReference::normalizeGallery($reference->gallery)) + ($reference->image ? 1 : 0) }} Bilder