whereNotNull('gallery')->get() as $brand) { $gallery = $brand->gallery ?? []; $changed = false; foreach ($gallery as $index => $item) { $caption = (string) ($item['caption'] ?? ''); $stripped = $this->stripPrefix($caption); if ($stripped !== $caption) { $gallery[$index]['caption'] = $stripped; $changed = true; $cleaned++; } } if ($changed) { $brand->gallery = CmsBrand::normalizeGallery($gallery); $brand->save(); } } $this->command?->info("Bildunterschriften bereinigt: {$cleaned}."); } private function stripPrefix(string $caption): string { foreach (self::PREFIXES as $prefix) { if (str_starts_with($caption, $prefix)) { return trim(substr($caption, strlen($prefix))); } } return $caption; } }