Files
fewo-stommer/app/Filament/Resources/Photos/Pages/ListPhotos.php
T
Lars StommerandClaude Opus 5.5 bb7eb62782 Inhaltsverwaltung: Bilder, Webseiten-Texte, Ausstattung, FAQ, Hinweis-Banner
- Bilder mit automatischen WebP-Webgrößen (640/1280/2048 px), Sortierung per Drag & Drop, Mehrfach-Upload, Import-Befehl photos:import
- Webseiten-Texte als feste, bearbeitbare Bausteine (config/content.php), Rich-Text bereinigt ausgegeben
- Ausstattung und FAQ aus der bisherigen Webseite übernommen
- Rolle Inhalte hat Zugriff auf alle Webseiten-Bereiche

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 10:19:51 +02:00

67 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Filament\Resources\Photos\Pages;
use App\Enums\PhotoCategory;
use App\Filament\Resources\Photos\PhotoResource;
use App\Models\Photo;
use App\Models\Property;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ListRecords;
use Filament\Support\Icons\Heroicon;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
class ListPhotos extends ListRecords
{
protected static string $resource = PhotoResource::class;
protected function getHeaderActions(): array
{
return [
Action::make('bulkUpload')
->label('Mehrere Bilder hochladen')
->icon(Heroicon::OutlinedArrowUpTray)
->authorize('create', Photo::class)
->modalDescription('Die Bildbeschreibung wird aus dem Dateinamen vorbelegt – bitte danach kurz anpassen.')
->schema([
FileUpload::make('files')
->label('Bilder')
->multiple()
->image()
->maxSize(25 * 1024)
->storeFiles(false)
->required(),
Select::make('category')
->label('Kategorie')
->options(PhotoCategory::class)
->default(PhotoCategory::Apartment)
->required(),
])
->action(function (array $data): void {
$propertyId = Property::query()->value('id');
$nextSort = (int) Photo::max('sort_order');
/** @var TemporaryUploadedFile $file */
foreach ($data['files'] as $file) {
$photo = Photo::create([
'property_id' => $data['category'] === PhotoCategory::Area->value ? null : $propertyId,
'category' => $data['category'],
'alt_text' => str(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME))->replace(['_', '-'], ' ')->squish()->ucfirst()->toString(),
'sort_order' => ++$nextSort,
]);
$photo->addMedia($file->getRealPath())
->usingFileName($file->getClientOriginalName())
->toMediaCollection(Photo::COLLECTION);
}
Notification::make()->title(count($data['files']).' Bilder hochgeladen')->success()->send();
}),
CreateAction::make()->label('Einzelnes Bild'),
];
}
}