Files
LarsandClaude Opus 5.5 8bcda9a4bc Wohnungsumschalter im Verwaltungsmenue und wohnungsbezogene Listen
Oben im Seitenmenue waehlt man die Wohnung; Listen, neue Eintraege, Belegungsplan
und Preise & Angebote folgen ihr. Ein geoeffneter Eintrag einer anderen Wohnung
schaltet auf diese um. Galerie und Ersatz-Titelbild der Website zeigen nur Fotos
der Wohnung des Bausteins und Fotos ohne Wohnung.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 18:40:13 +01:00

80 lines
3.2 KiB
PHP
Raw Permalink 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\Concerns\ListsCurrentProperty;
use App\Filament\Resources\Photos\PhotoResource;
use App\Models\Photo;
use App\Models\Property;
use App\Support\CurrentProperty;
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 Illuminate\Database\Eloquent\Builder;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
class ListPhotos extends ListRecords
{
use ListsCurrentProperty;
protected static string $resource = PhotoResource::class;
/**
* Photos without an apartment (e.g. the area) belong to every apartment.
*/
protected function scopeToProperty(Builder $query, Property $property): Builder
{
return $query->where(fn (Builder $query) => $query->where('property_id', $property->id)->orWhereNull('property_id'));
}
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 = app(CurrentProperty::class)->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'),
];
}
}