Skip to content

Commit

Permalink
Add getAttributeTranslations function
Browse files Browse the repository at this point in the history
  • Loading branch information
petrzpav committed Nov 20, 2024
1 parent 77bfea3 commit f052b5e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Traits/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ public function getAttribute($key)
return $this->translate($key, app()->getLocale(), app()->getFallbackLocale());
}

/**
* Return translations accroding to config.languages
*/
public function getAttributeTranslations($key)
{
foreach (config('languages') as $locale => $language) {
$translations[$locale] = $this->translate($key, $locale, app()->getFallbackLocale());
}

return $translations;
}

/**
* Set the attribute to the model.
* Save translation if attribute is translatable.
Expand Down

0 comments on commit f052b5e

Please sign in to comment.