public function scopeTranslated(Builder $query)
    {
        $mainTable = $this->getTable();
        $keyName = $this->getKeyName();
        $relKeyName = $this->getRelationKey();
        $localeKey = $this->getLocaleKey();
        $joinTable = $this->getTranslationModel()->getTable();
        $langId = \localizer\locale()->id();

        $alias = "tt";

        if ($this->isQueryWithoutColumns($query)) {
            $this->fillQueryWithTranslatedColumns($query, $mainTable, $keyName, $alias);
        }

        $query->leftJoin(
            "{$joinTable} AS {$alias}",
            function ($join) use ($mainTable, $keyName, $relKeyName, $localeKey, $alias, $langId) {
                $join->on("{$mainTable}.{$keyName}", '=', "{$alias}.{$relKeyName}")
                     ->where($localeKey, '=', (int)$langId);
            }
        );

        return $query;
    }
public function scopeTranslated(Builder $query)
    {
        $mainTable = $this->getTable();
        $keyName = $this->getKeyName();
        $relKeyName = $this->getRelationKey();
        $localeKey = $this->getLocaleKey();
        $joinTable = $this->getTranslationModel()->getTable();
        $langId = \localizer\locale()->id();

        $alias = "tt";

        if ($this->isQueryWithoutColumns($query)) {
            $this->fillQueryWithTranslatedColumns($query, $mainTable, $keyName, $alias);
        }

        $query->leftJoin(
            "{$joinTable} AS {$alias}",
            function ($join) use ($mainTable, $keyName, $relKeyName, $localeKey, $alias, $langId) {
                $join->on("{$mainTable}.{$keyName}", '=', "{$alias}.{$relKeyName}")
                     ->where($localeKey, '=', (int)$langId);
            }
        );

        return $query;
    }
public function scopeTranslated ( Builder $ query ) { $ mainTable = $ this -> getTable ( ) ; $ keyName = $ this -> getKeyName ( ) ; $ relKeyName = $ this -> getRelationKey ( ) ; $ localeKey = $ this -> getLocaleKey ( ) ; $ joinTable = $ this -> getTranslationModel ( ) -> getTable ( ) ; $ langId = \ localizer \ locale ( ) -> id ( ) ; $ alias = "tt" ; if ( $ this -> isQueryWithoutColumns ( $ query ) ) { $ this -> fillQueryWithTranslatedColumns ( $ query , $ mainTable , $ keyName , $ alias ) ; } $ query -> leftJoin ( "{$joinTable} AS {$alias}" , function ( $ join ) use ( $ mainTable , $ keyName , $ relKeyName , $ localeKey , $ alias , $ langId ) { $ join -> on ( "{$mainTable}.{$keyName}" , '=' , "{$alias}.{$relKeyName}" ) -> where ( $ localeKey , '=' , ( int ) $ langId ) ; } ) ; return $ query ; }
Allows fetching "Translatable" items with translations

@note      : To limit the number of columns during query it's recommended to add select($columns) statement
before calling translated() scope Examples: there are a few ways to get id=>title associative array
for all posts:
@example1  : Post::active()->select(['post.id', 'tt.title'])->translated()->lists('title', 'id');
@example2  : Post::active()->translated()->lists('title', 'id'); will return the same list, but query will
contain all translated columns, which can be a performance issue.
@example3  : Post::active()->select(['post.id', 'title', 'description'])->translated()->get();
- will return all posts and query will contain only specified columns
@example4  : Post::active()->translated()->get();
- the same result, but query contains all "Translatable" columns
@param Builder $query
@hidden    - Hide this scope from AdminArchitect parser.
@return Builder
Allows fetching Translatable items with translations