From 37a09c4275f33e61b488792d60d8cd1630c72c59 Mon Sep 17 00:00:00 2001 From: Nicolas Widart Date: Sun, 17 Sep 2017 12:31:02 +0200 Subject: [PATCH] Handle fields manually in order to have empty translations too --- Modules/Page/Transformers/FullPageTransformer.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Modules/Page/Transformers/FullPageTransformer.php b/Modules/Page/Transformers/FullPageTransformer.php index 1e2bbea98..1ddd52523 100644 --- a/Modules/Page/Transformers/FullPageTransformer.php +++ b/Modules/Page/Transformers/FullPageTransformer.php @@ -3,6 +3,7 @@ namespace Modules\Page\Transformers; use Illuminate\Http\Resources\Json\Resource; +use Mcamara\LaravelLocalization\Facades\LaravelLocalization; class FullPageTransformer extends Resource { @@ -14,9 +15,12 @@ public function toArray($request) 'is_home' => $this->is_home, ]; - foreach ($this->translations as $pageTranslation) { - $pageData[$pageTranslation->locale] = $pageTranslation; + foreach (LaravelLocalization::getSupportedLocales() as $locale => $supportedLocale) { + foreach ($this->translatedAttributes as $translatedAttribute) { + $pageData[$locale][$translatedAttribute] = $this->translateOrNew($locale)->$translatedAttribute; + } } + foreach ($this->tags as $tag) { $pageData['tags'][] = $tag->name; }