> $texts */ $texts = require database_path('seeders/data/category-descriptions.php'); $rows = []; $written = 0; foreach ($texts as $slug => $byLocale) { $category = Category::query() ->whereHas('translations', fn ($query) => $query->where('locale', 'de')->where('slug', $slug)) ->with('translations') ->first(); if (! $category) { $rows[] = [$slug, '—', 'Kategorie nicht gefunden']; continue; } foreach ($byLocale as $locale => $text) { /** @var CategoryTranslation|null $translation */ $translation = $category->translations->firstWhere('locale', $locale); if (! $translation) { $rows[] = [$slug, $locale, 'keine Übersetzung']; continue; } if (filled($translation->description) && ! $this->option('force')) { $rows[] = [$slug, $locale, 'bereits vorhanden, übersprungen']; continue; } $rows[] = [$slug, $locale, mb_strimwidth($text, 0, 60, '…')]; if (! $this->option('dry-run')) { $translation->forceFill(['description' => $text])->save(); $written++; } } } $this->table(['Kategorie', 'Sprache', 'Ergebnis'], $rows); if ($this->option('dry-run')) { $this->info('[Dry-Run] Nichts geschrieben.'); return self::SUCCESS; } WebPageCache::flush(); $this->info(sprintf('%d Beschreibungen geschrieben, Seiten-Cache geleert.', $written)); return self::SUCCESS; } }