Skip to content

Commit bf24d3d

Browse files
committed
Update Translatable.php
1 parent e85c2a9 commit bf24d3d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Eloquent/Traits/Translatable.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ protected static function bootTranslatable()
2626
foreach ((array)with(new self)->translatable as $item) {
2727
if ($model->{$item}) {
2828
if (is_array($model->{$item})) {
29-
$model->{$item} = json_encode(array_filter($model->{$item}, function($var) {
29+
$translations = array_filter($model->{$item}, function($var) {
3030
return strlen(strip_tags(trim($var))) != 0;
31-
}));
31+
});
32+
$model->{$item} = count($translations) ? json_encode($translations) : '';
3233
} elseif (is_string($model->{$item}) && !is_array(json_decode($model->{$item}, true))) {
3334
$model->{$item} = json_encode([config('app.locale') => $model->{$item}]);
3435
}
@@ -73,9 +74,10 @@ protected static function bootTranslatable()
7374
$original_locales[$locale] = $value;
7475
}
7576
//remove empty translations from array and save as json
76-
$model->{$item} = json_encode(array_filter($original_locales, function($var) {
77+
$translations = array_filter($original_locales, function($var) {
7778
return strlen(strip_tags(trim($var))) != 0;
78-
}));
79+
});
80+
$model->{$item} = count($translations) ? json_encode($translations) : '';
7981
} else {
8082
//TODO: update locales in translation model
8183
//

0 commit comments

Comments
 (0)