spatie/laravel-translatable
Adds HasTranslations to Eloquent models to store translations in JSON columns—no extra tables. Define translatable attributes via PHP 8 attribute or $translatable property, then set/get per-locale values while model accessors return the current app locale.
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?