pressReleaseId = $pressReleaseId; } public function upload(ImageService $imageService): void { $pressRelease = $this->getPressRelease(); $this->authorize('update', $pressRelease); if (! $this->canChangeImages($pressRelease)) { $this->addError('newImage', __('Bilder können nur bei Entwürfen oder abgelehnten PMs geändert werden.')); return; } $this->validate([ 'newImage' => ['required', 'image', 'mimes:jpeg,jpg,png,webp', 'max:'.(int) (ImageService::MAX_PRESS_RELEASE_IMAGE_BYTES / 1024)], 'newTitle' => ['nullable', 'string', 'max:120'], 'newCopyright' => ['nullable', 'string', 'max:255'], ]); $stored = $imageService->storePressReleaseImage($this->newImage, $pressRelease->id); if ($this->newIsPreview) { $pressRelease->images()->update(['is_preview' => false]); } $pressRelease->images()->create([ 'disk' => 'public', 'path' => $stored['path'], 'variants' => $stored['variants'], 'title' => $this->newTitle ?: null, 'copyright' => $this->newCopyright ?: null, 'is_preview' => $this->newIsPreview, 'sort_order' => ((int) $pressRelease->images()->max('sort_order')) + 1, 'width' => $stored['width'], 'height' => $stored['height'], 'mime' => $stored['mime'], ]); $this->reset(['newImage', 'newTitle', 'newCopyright', 'newIsPreview']); Flux::toast(text: __('Bild hochgeladen.'), variant: 'success'); } public function setPreview(int $imageId): void { $pressRelease = $this->getPressRelease(); $this->authorize('update', $pressRelease); $image = $pressRelease->images()->whereKey($imageId)->first(); if (! $image) { return; } $pressRelease->images()->where('id', '!=', $image->id)->update(['is_preview' => false]); $image->update(['is_preview' => true]); Flux::toast(text: __('Vorschaubild gesetzt.'), variant: 'success'); } public function moveUp(int $imageId): void { $this->swapSortOrder($imageId, -1); } public function moveDown(int $imageId): void { $this->swapSortOrder($imageId, 1); } public function remove(int $imageId, ImageService $imageService): void { $pressRelease = $this->getPressRelease(); $this->authorize('update', $pressRelease); if (! $this->canChangeImages($pressRelease)) { return; } $image = $pressRelease->images()->whereKey($imageId)->first(); if (! $image) { return; } $imageService->deletePressReleaseImage($image->disk, $image->path, $image->variants); $image->delete(); Flux::toast(text: __('Bild entfernt.'), variant: 'success'); } public function with(): array { $pressRelease = $this->getPressRelease(); return [ 'images' => $pressRelease->images() ->orderBy('sort_order') ->orderBy('id') ->get(), 'canEdit' => auth()->user()?->can('update', $pressRelease) === true && $this->canChangeImages($pressRelease), ]; } private function swapSortOrder(int $imageId, int $direction): void { $pressRelease = $this->getPressRelease(); $this->authorize('update', $pressRelease); if (! $this->canChangeImages($pressRelease)) { return; } $images = $pressRelease->images()->orderBy('sort_order')->orderBy('id')->get(); $currentIndex = $images->search(fn (PressReleaseImage $image) => $image->id === $imageId); if ($currentIndex === false) { return; } $targetIndex = $currentIndex + $direction; if ($targetIndex < 0 || $targetIndex >= $images->count()) { return; } $current = $images[$currentIndex]; $target = $images[$targetIndex]; $currentSort = $current->sort_order; $current->update(['sort_order' => $target->sort_order]); $target->update(['sort_order' => $currentSort]); } private function getPressRelease(): PressRelease { return PressRelease::withoutGlobalScopes() ->findOrFail($this->pressReleaseId); } private function canChangeImages(PressRelease $pressRelease): bool { if (auth()->user()?->canAccessAdmin()) { return ! in_array( $pressRelease->status, [PressReleaseStatus::Archived], true, ); } return in_array( $pressRelease->status, [PressReleaseStatus::Draft, PressReleaseStatus::Rejected], true, ); } }; ?>
{{ __('Bilder') }} {{ count($images) }}
@if($canEdit)
{{ __('Neues Bild hinzufügen') }}
{{ __('Hochladen') }}
@endif @if($images->isEmpty())
{{ __('Noch keine Bilder hinterlegt.') }}
@else
@foreach($images as $image)
@if($image->variantUrl('thumb') ?? $image->url()) {{ $image->title ?? '' }} @endif @if($image->is_preview) {{ __('Vorschau') }} @endif
@if($image->title)

{{ $image->title }}

@endif @if($image->copyright)

{{ $image->copyright }}

@endif
@if($image->width && $image->height) {{ $image->width }}×{{ $image->height }} @endif @if(is_array($image->variants)) {{ count($image->variants) }}× variant @endif
@if($canEdit)
@if(! $image->is_preview) @endif
@endif
@endforeach
@endif