27 lines
811 B
PHP
27 lines
811 B
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use App\Repositories\ModelTranslationRepository;
|
|
|
|
trait ModelAttributeTranslationsUpdattable
|
|
{
|
|
private function updateAttributeTranslations($model, $attribute, $translations)
|
|
{
|
|
$transRepo = app(ModelTranslationRepository::class);
|
|
$transRepo->setTranslatedModel($model);
|
|
$locales = app('SiteState')->languages;
|
|
$defaultLocale = config('app.locale');
|
|
|
|
foreach ($translations as $locale => $translation) {
|
|
if(in_array($locale, $locales)) {
|
|
$transRepo->updateModelTranslation($model->id, $attribute, $locale, $translation);
|
|
}
|
|
}
|
|
if(isset($translations[$defaultLocale])) {
|
|
$model->$attribute = $translations[$defaultLocale];
|
|
$model->save();
|
|
}
|
|
}
|
|
}
|