public function scopeI18N($query, $locale = null)
    {
        $i18nTranAlias = "i18n_translation";
        $i18nAlias     = "i18n";
        $primary       = $this->primaryKey;
        $i18nPrimary   = $this->i18n_primary;
        $table         = $this->table;
        $i18n_table    = (new $this->i18n_class())->getTable();

        if ($locale) {
            $query->leftJoin(\DB::raw("
            (
                SELECT {$i18nTranAlias}.*
                FROM {$i18n_table} as {$i18nTranAlias}
                WHERE {$i18nTranAlias}.{$this->getI18NCodeField()} = '{$locale}'
            ) as {$i18nAlias}"
            ), function ($join) use ($i18nAlias, $primary, $i18nPrimary, $table) {
                $join->on("{$i18nAlias}.{$i18nPrimary}", "=", "{$table}.{$primary}");
            });
        } else {
            $query->leftJoin("{$i18n_table} as {$i18nAlias}", "{$i18nAlias}.{$i18nPrimary}", "=", "{$table}.{$primary}");
        }

        return $query;
    }
public function scopeI18N($query, $locale = null)
    {
        $i18nTranAlias = "i18n_translation";
        $i18nAlias     = "i18n";
        $primary       = $this->primaryKey;
        $i18nPrimary   = $this->i18n_primary;
        $table         = $this->table;
        $i18n_table    = (new $this->i18n_class())->getTable();

        if ($locale) {
            $query->leftJoin(\DB::raw("
            (
                SELECT {$i18nTranAlias}.*
                FROM {$i18n_table} as {$i18nTranAlias}
                WHERE {$i18nTranAlias}.{$this->getI18NCodeField()} = '{$locale}'
            ) as {$i18nAlias}"
            ), function ($join) use ($i18nAlias, $primary, $i18nPrimary, $table) {
                $join->on("{$i18nAlias}.{$i18nPrimary}", "=", "{$table}.{$primary}");
            });
        } else {
            $query->leftJoin("{$i18n_table} as {$i18nAlias}", "{$i18nAlias}.{$i18nPrimary}", "=", "{$table}.{$primary}");
        }

        return $query;
    }
public function scopeI18N ( $ query , $ locale = null ) { $ i18nTranAlias = "i18n_translation" ; $ i18nAlias = "i18n" ; $ primary = $ this -> primaryKey ; $ i18nPrimary = $ this -> i18n_primary ; $ table = $ this -> table ; $ i18n_table = ( new $ this -> i18n_class ( ) ) -> getTable ( ) ; if ( $ locale ) { $ query -> leftJoin ( \ DB :: raw ( "
            (
                SELECT {$i18nTranAlias}.*
                FROM {$i18n_table} as {$i18nTranAlias}
                WHERE {$i18nTranAlias}.{$this->getI18NCodeField()} = '{$locale}'
            ) as {$i18nAlias}" ) , function ( $ join ) use ( $ i18nAlias , $ primary , $ i18nPrimary , $ table ) { $ join -> on ( "{$i18nAlias}.{$i18nPrimary}" , "=" , "{$table}.{$primary}" ) ; } ) ; } else { $ query -> leftJoin ( "{$i18n_table} as {$i18nAlias}" , "{$i18nAlias}.{$i18nPrimary}" , "=" , "{$table}.{$primary}" ) ; } return $ query ; }
Join I18N data to this

@param $query Builder
@param $locale string|null
@return  Builder
Join I18N data to this