Skip to content

Commit

Permalink
Handle fields manually in order to have empty translations too
Browse files Browse the repository at this point in the history
  • Loading branch information
nWidart committed Sep 17, 2017
1 parent 77fb616 commit 37a09c4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Modules/Page/Transformers/FullPageTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Modules\Page\Transformers;

use Illuminate\Http\Resources\Json\Resource;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;

class FullPageTransformer extends Resource
{
Expand All @@ -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;
}
Expand Down

0 comments on commit 37a09c4

Please sign in to comment.