spatie/laravel-translatable
Add multilingual fields to Eloquent models using a simple HasTranslations trait. Store translations as JSON on the model (no extra tables). Set/get translations per locale, switch app locale, fetch all translations, and even translate nested JSON keys via -> notation.
You can replace all the translations for a single key using this method:
public function replaceTranslations(string $key, array $translations)
Here's an example:
$translations = ['en' => 'hello', 'es' => 'hola'];
$newsItem->setTranslations('hello', $translations);
$newsItem->getTranslations(); // ['en' => 'hello', 'es' => 'hola']
$newTranslations = ['en' => 'hello'];
$newsItem->replaceTranslations('hello', $newTranslations);
$newsItem->getTranslations(); // ['en' => 'hello']
How can I help you explore Laravel packages today?