Astrotomic / laravel-translatable

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

How can I load hasMany translated relationships ? #237

Closed sachindn closed 3 years ago

sachindn commented 3 years ago

I have a model User and UserTranslations which are working fine.

I have a relationship from User to UserCertificates Model.

And certificates also have translations to How can I get UserCertificates in default or given locale.

When I am loading $user->certificates it is returning in all locale not in default.

Thanks

Gummibeer commented 3 years ago

Hey, also the other models will use the same locale as all your models. I think what you mean is that there's a translations "attribute" if you do toArray() or toJson() which contains all translations. This is the correct behavior. You shouldn't do toArray() to get an API response. Instead you should use an eloquent API resource class and map your attributes explicitly. https://laravel.com/docs/8.x/eloquent-resources

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days