Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Translatable Laravel Package

astrotomic/laravel-translatable

Laravel package for translatable Eloquent models. Store model translations in the database and automatically fetch/save multilingual attributes based on locale, reducing boilerplate when working with multi-language content.

View on GitHub
Deep Wiki
Context7

Forms

Forms

If you want to translate a field in multiple locales with a single form you can use the overridden fill() method which allows you to pass in an array with the locales as first array key and the translated attributes in the sub-array.

$post->fill([
  'en' => [
    'title' => 'My first edited post',
  ],
  'de' => [
    'title' => 'Mein erster bearbeiteter Beitrag',
  ],
]);

Request as array syntax

To achieve this structure in your form - to prevent manipulating the form data just to save them. You can use the input name array [] syntax.

<input type="text" name="en[title]" />
<input type="text" name="de[title]" />

Request as plain syntax

If you want, you can structure the request inputs in colon notation too. Notice that with this approach the attribute goes first.

<input type="text" name="title:en" />
<input type="text" name="title:de" />

Saving the request

Both ways are ready to save the translatable attributes to the model without any other modification.

public function update(Request $request, Post $post)
{
  $post->update($request->all());
}

Updating the default locale

You can update the default locale attributes by accessing the translatable attributes from the model itself.

$post->title = 'My first post'; // Will update the English translatable model
$post->fill(['title' => 'My first post']); // Will update the English translatable model
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope