Stars: 1106
Forks: 136
Pull Requests: 139
Issues: 226
Watchers: 16
Last Updated: 2023-09-05 08:31:14
A Laravel package for multilingual models
License: MIT License
Languages: PHP
If you want to store translations of your models into the database, this package is for you.
This is a Laravel package for translatable models. Its goal is to remove the complexity in retrieving and storing multilingual model instances. With this package you write less code, as the translations are being fetched/saved when you fetch/save your instance.
The full documentation can be found at GitBook.
composer require astrotomic/laravel-translatable
$post = Post::first();
echo $post->translate('en')->title; // My first post
App::setLocale('en');
echo $post->title; // My first post
App::setLocale('de');
echo $post->title; // Mein erster Post
$post = Post::first();
echo $post->translate('en')->title; // My first post
$post->translate('en')->title = 'My cool post';
$post->save();
$post = Post::first();
echo $post->translate('en')->title; // My cool post
$data = [
'author' => 'Gummibeer',
'en' => ['title' => 'My first post'],
'fr' => ['title' => 'Mon premier post'],
];
$post = Post::create($data);
echo $post->translate('fr')->title; // Mon premier post
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details. You could also be interested in CODE OF CONDUCT.
If you discover any security related issues, please check SECURITY for steps to report it.
Package | Laravel | PHP |
---|---|---|
v11.12 - v11.12 | 8.* / 9.* / 10.* |
^8.0 |
v11.10 - v11.11 | 8.* / 9.* |
^8.0 |
v11.6 - v11.9 | 5.8.* / 6.* / 7.* / 8.* |
>=7.2 |
v11.4 - v11.5 | 5.6.* / 5.7.* / 5.8.* / 6.* |
>=7.1.3 |
v11.0 - v11.3 | 5.6.* / 5.7.* / 5.8.* |
>=7.1.3 |
You're free to use this package, but if it makes it to your production environment I would highly appreciate you buying the world a tree.
It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you contribute to my forest you’ll be creating employment for local families and restoring wildlife habitats.
You can buy trees at offset.earth/treeware
Read more about Treeware at treeware.earth