Skip to content

Commit de47dcc

Browse files
author
Steven
committed
Refactoring for improve readability
1 parent 3ee1fe1 commit de47dcc

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Translatable/Traits/Relationship.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@ public function getTranslationRelationKey(): string
6363

6464
public function translation(): HasOne
6565
{
66-
if ($this->useFallback() && ! $this->translations()->where('locale', $this->locale())->exists()) {
67-
return $this
68-
->hasOne($this->getTranslationModelName(), $this->getTranslationRelationKey())
69-
->where('locale', $this->getFallbackLocale());
70-
}
71-
7266
return $this
7367
->hasOne($this->getTranslationModelName(), $this->getTranslationRelationKey())
74-
->where('locale', $this->locale());
68+
->where('locale', $this->localeOrFallback());
69+
}
70+
71+
public function localeOrFallback()
72+
{
73+
return $this->useFallback() && ! $this->translations()->where('locale', $this->locale())->exists()
74+
? $this->getFallbackLocale()
75+
: $this->locale();
7576
}
7677

7778
public function translations(): HasMany

0 commit comments

Comments
 (0)