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 install the package via composer:
composer require spatie/laravel-translatable
The required steps to make a model translatable are:
Spatie\Translatable\HasTranslations-trait.$translatable which holds an array with all the names of attributes you wish to make translatable.json-datatype in your database. If your database doesn't support json-columns, use text.Here's an example of a prepared model:
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class NewsItem extends Model
{
use HasTranslations;
public array $translatable = ['name'];
}
How can I help you explore Laravel packages today?