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.
Returns all posts being translated in english
Post::translatedIn('en')->get();
Returns all posts not being translated in english
Post::notTranslatedIn('en')->get();
Returns all posts with existing translations
Post::translated()->get();
Eager loads translation relationship only for the default and fallback (if enabled) locale
Post::withTranslation()->get();
Returns an array containing pairs of post ids and the translated title attribute
Post::listsTranslations('title')->get()->toArray();
[
['id' => 1, 'title' => 'My first post'],
['id' => 2, 'title' => 'My second post']
]
Filters posts by checking the translation against the given value
Post::whereTranslation('title', 'My first post')->first();
Post::whereTranslation('title', 'My first post')
->orWhereTranslation('title', 'My second post')
->get();
Post::whereTranslationLike('title', '%first%')->first();
Post::whereTranslationLike('title', '%first%')
->orWhereTranslationLike('title', '%second%')
->get();
Sorts the model by a given translation column value
Post::orderByTranslation('title')->get()
How can I help you explore Laravel packages today?