option('category')); if ($category === null) { $this->error('Unbekannte Kategorie. Erlaubt: '.implode(', ', array_column(PhotoCategory::cases(), 'value'))); return self::FAILURE; } $files = glob(rtrim((string) $this->argument('directory'), '/\\').'/*.{jpg,jpeg,png,webp,JPG,JPEG,PNG,WEBP}', GLOB_BRACE) ?: []; $propertyId = $category === PhotoCategory::Area ? null : Property::query()->value('id'); $sort = (int) Photo::max('sort_order'); foreach ($files as $file) { $photo = Photo::create([ 'property_id' => $propertyId, 'category' => $category, 'alt_text' => str(pathinfo($file, PATHINFO_FILENAME))->replace(['_', '-'], ' ')->squish()->ucfirst()->toString(), 'sort_order' => ++$sort, ]); $photo->addMedia($file)->preservingOriginal()->toMediaCollection(Photo::COLLECTION); $this->line("✓ {$photo->alt_text}"); } $this->info(count($files).' Bilder importiert.'); return self::SUCCESS; } }