Dynamic languages using spatie's package
I am saving a list of languages per entry in my articles table, so for example,
$article->languages can be ['es','de'] and sometimes it can be ['fr','nl'].. etc. Now, i worked with spatie/laravel-translatable in the past with no problem at all, when getTranslatableLocales() has a fixed set of languages, but when trying to populate the locale switcher dynamically by $article->languages - it fallbacks to the default config once language is changed.
Here's how im trying to implement it at the moment onArticleResource.php-
`php
public static function getTranslatableLocales(): array
{
$recordId = request()->route('record');
$defaultLanguages = config('languages');
if ($recordId) {
$article = Article::find($recordId);
if ($article && !empty($article->languages)) {
return $article->languages;
}
}
return $defaultLanguages;
}
```
I noticed that once i change the language in the locale switcher (a simple Actions\LocaleSwitcher::make() on getHeaderActions()) - the $recordId is emptied, hence it retrieves the $defaultLnaguages instead. I guess there's a more way to access the current record instead of request()->route('record')`