Skip to content

Commit dee9466

Browse files
author
Tihomir Banov
committed
Add scopeWithTranslations mehod
1 parent a3a06d7 commit dee9466

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Despark/LaravelDbLocalization/i18nModelTrait.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ public function translate($locale = false)
100100
return $translation;
101101
}
102102

103+
public function scopeWithTranslations($query, $locale = 'en')
104+
{
105+
$i18nId = $this->getI18nId($locale);
106+
$translatorTable = new $this->translator();
107+
$translatorTableName = $translatorTable->getTable();
108+
109+
return $query->join(
110+
$translatorTableName,
111+
$translatorTableName.'.'.$this->getTranslatorField(), '=', $this->getTable().'.id',
112+
'left'
113+
)
114+
->where($translatorTableName.'.'.$this->getLocaleField(), '=', $i18nId);
115+
}
116+
103117
/**
104118
* Create new record.
105119
*

0 commit comments

Comments
 (0)