Skip to content

Commit

Permalink
Empty value remove translation
Browse files Browse the repository at this point in the history
  • Loading branch information
petrzpav committed Nov 13, 2024
1 parent 82bc1af commit f74bfb3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Traits/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ public function setAttribute($key, $value)

public function setTranslation($attribute, $locale, $value)
{
if (! $value) {
$this->translations()->updateOrCreate(
['attribute' => $attribute, 'locale' => $locale],
['value' => $value]
);
} else {
$this->translations()->where('attribute', $attribute)->where('locale', $locale)->delete();
}
$fallbackLocale = app()->getFallbackLocale();
$this->translations()->updateOrCreate(
['attribute' => $attribute, 'locale' => $locale],
['value' => $value]
);
Cache::forget($this->getTraslationCacheKey($attribute, $locale, $fallbackLocale));
}

Expand Down

0 comments on commit f74bfb3

Please sign in to comment.