Voyager supports multiple languages for your models.To get started, you need to configure some things first.
First you need to define some locales
in your config/voyager.php
file and enable
multilanguage:
After that you need to include the Translatable
Trait in your model and define the translatable attributes:
Now you will see a language-selection in your Pages BREAD.
If you do not define locale, the current application locale will be used. You can pass in your own locale as a string. If you do not define fallbackLocale, the current application fallback locale will be used. You can pass your own locale as a string. If you want to turn the fallback locale off, pass false. If no values are found for the model for a specific attribute, either for the locale or the fallback, it will set that attribute to null.
If you do not define locale, the current application locale will be used. You can pass in your own locale as a string. If you do not define fallbackLocale, the current application fallback locale will be used. You can pass in your own locale as a string. If you want to turn the fallback locale off, pass false. If no values are found for the model for a specific attribute, either for the locale or the fallback, it will set that attribute to null.
This will update or create the translation for title of the post with the locale da. Please note that if a modified attribute is not translatable, then it will make the changes directly to the model itself. Meaning that it will overwrite the attribute in the language set as default.
To search for a translated value, you can use the whereTranslation
method.
For example, to search for the slug of a post, you'd use
whereTranslation
accepts the following parameter:
field
the field you want to search in
operator
the operator. Defaults to =
. Also can be the value (Same as where)
value
the value you want to search for
locales
the locales you want to search in as an array. Leave as null
if you want to search all locales
default
also search in the default value/locale. Defaults to true.