Astrotomic / laravel-translatable

A Laravel package for multilingual models
https://docs.astrotomic.info/laravel-translatable/
MIT License
1.23k stars 155 forks source link

How to load translation only for the current locale ? #298

Closed Eyad-Bereh closed 1 year ago

Eyad-Bereh commented 1 year ago

Greetings ! When I call a translatable entity, all translations get loaded from the database, even those which I don't need them To be more clear, I have a translatable entity that has 2 languages Arabic and English, but when I load the entity in the controller translations for both languages get loaded:

image

This has a bad impact on performance, I want to only load translations from the currently active locale (either Arabic or English)

Eyad-Bereh commented 1 year ago

i've figured something out, if I autoload the translation relationship (translation in singular, not in plural) in the model:

protected $with = ["translation"];

I can get the desired result, is there any better way to do this ?

Gummibeer commented 1 year ago

You already got the solution - loading the translation (singular) relationship.