1

I am using voyager admin laravel that includes its own translations table and I have two tables categories and products that have a relationship, each product belongs to a category. Now when I fill products data and switch between languages category field doesn't change, it shows me always the default language. any help?

  • 1
    Show Us Your code –  Jun 10 '19 at 09:25
  • There is no code !! it is `voyager admin` .. all I did is follow instructions of how to add languages tab by adding this simple code `use Translatable; protected $translatable = ['title', 'description', 'warranty'];` in Product model. – nashwa ghazy Jun 10 '19 at 12:41

1 Answers1

0

In the view use the getTranslatedAttribute() method.

For example you list your products in foreach then use the following:

$product->category->getTranslatedAttribute('category_name', 'current_lang', 'fallback_lang')

category is the relationship (category() in the model).

That's it.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Hódos Gábor
  • 109
  • 1
  • 7