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'), ]; } }