Наследование: extends Illuminate\Database\Eloquent\Model
 public function truncateTranslations($group = '*')
 {
     if ($group === '*') {
         Translation::truncate();
     } else {
         $this->translation->getConnection()->affectingStatement("DELETE FROM ltm_translations WHERE `group` = ?", [$group]);
     }
 }
    /**
     * @param $locale
     * @param $db_group
     * @param $translations
     * @param $replace
     */
    protected function importTranslationFile($locale, $db_group, $translations, $replace)
    {
        $connectionName = $this->getConnectionName();
        $ltm_translations = $this->getTranslationsTableName();
        $dbTranslations = $this->translation->hydrateRaw(<<<SQL
SELECT * FROM {$ltm_translations} WHERE locale = ? AND `group` = ?

SQL
, [$locale, $db_group], $connectionName);
        $timeStamp = 'now()';
        $dbTransMap = [];
        $dbTranslations->each(function ($trans) use(&$dbTransMap, $connectionName) {
            $dbTransMap[$trans->key] = $trans;
        });
        $values = [];
        $statusChangeOnly = [];
        foreach ($translations as $key => $value) {
            $value = (string) $value;
            if (array_key_exists($key, $dbTransMap)) {
                $translation = $dbTransMap[$key];
                unset($dbTransMap[$key]);
            } else {
                $translation = new Translation(array('locale' => $locale, 'group' => $db_group, 'key' => $key));
                $translation->setConnection($connectionName);
            }
            // Importing from the source, status is always saved. When it is changed by the user, then it is changed.
            //$newStatus = ($translation->value === $value || !$translation->exists) ? Translation::STATUS_SAVED : Translation::STATUS_CHANGED;
            // Only replace when empty, or explicitly told so
            if ($replace || !$translation->value) {
                $translation->value = $value;
            }
            $translation->is_deleted = 0;
            $translation->saved_value = $value;
            $newStatus = $translation->value === $translation->saved_value ? Translation::STATUS_SAVED : ($translation->status === Translation::STATUS_SAVED ? Translation::STATUS_SAVED_CACHED : Translation::STATUS_CHANGED);
            if ($newStatus !== (int) $translation->status) {
                $translation->status = $newStatus;
            }
            if (!$translation->exists) {
                $sql = '(' . self::dbValue($translation->status, Translation::STATUS_SAVED) . ',' . self::dbValue($translation->locale) . ',' . self::dbValue($translation->group) . ',' . self::dbValue($translation->key) . ',' . self::dbValue($translation->value) . ',' . self::dbValue($translation->created_at, $timeStamp) . ',' . self::dbValue($translation->updated_at, $timeStamp) . ',' . self::dbValue($translation->source) . ',' . self::dbValue($translation->saved_value) . ',' . self::dbValue($translation->is_deleted, 0) . ',' . self::dbValue($translation->was_used, 0) . ')';
                $values[] = $sql;
            } else {
                if ($translation->isDirty()) {
                    if ($translation->isDirty(['value', 'source', 'saved_value', 'was_used'])) {
                        $translation->save();
                    } else {
                        if (!array_key_exists($translation->status, $statusChangeOnly)) {
                            $statusChangeOnly[$translation->status] = $translation->id;
                        } else {
                            $statusChangeOnly[$translation->status] .= ',' . $translation->id;
                        }
                    }
                }
            }
            $this->imported++;
        }
        // now batch update those with status changes only
        $updated_at = new Carbon();
        foreach ($statusChangeOnly as $status => $translationIds) {
            $this->getConnection()->affectingStatement(<<<SQL
UPDATE {$ltm_translations} SET status = ?, is_deleted = 0, updated_at = ? WHERE id IN ({$translationIds})
SQL
, [$status, $updated_at]);
        }
        //$sql = "INSERT INTO `ltm_translations`(status, locale, `group`, `key`, value, created_at, updated_at, source, saved_value, is_deleted, was_used) VALUES ";
        // now process all the new translations that were not in the files
        if ($replace == 2) {
            // we delete all translations that were not in the files
            if ($dbTransMap) {
                $translationIds = '';
                foreach ($dbTransMap as $translation) {
                    $translationIds .= ',' . $translation->id;
                }
                $translationIds = trim_prefix($translationIds, ',');
                $this->getConnection()->unprepared(<<<SQL
DELETE FROM {$ltm_translations} WHERE id IN ({$translationIds})
SQL
);
            }
        } else {
            // update their status
            foreach ($dbTransMap as $translation) {
                // mark it as saved cached or changed
                if ((int) $translation->status === Translation::STATUS_SAVED) {
                    $translation->status = Translation::STATUS_SAVED_CACHED;
                    $translation->save();
                }
            }
        }
        if ($values) {
            $sql = "INS" . "ERT INTO `{$ltm_translations}`(status, locale, `group`, `key`, value, created_at, updated_at, source, saved_value, is_deleted, was_used) VALUES " . implode(",", $values);
            //$this->getConnection()->unprepared('LOCK TABLES `ltm_translations` WRITE');
            try {
                $this->getConnection()->unprepared($sql);
            } catch (\Exception $e) {
                $tmp = 0;
            }
            //$this->getConnection()->unprepared('UNLOCK TABLES');
        }
    }
 public function postEdit(HttpRequest $request, $group)
 {
     if (!in_array($group, $this->manager->getConfig('exclude_groups'))) {
         $name = $request->get('name');
         $value = $request->get('value');
         list($locale, $key) = explode('|', $name, 2);
         $translation = Translation::firstOrNew(array('locale' => $locale, 'group' => $group, 'key' => $key));
         // strip off trailing spaces and eol's and &nbsps; that seem to be added when multiple spaces are entered in the x-editable textarea
         $value = trim(str_replace(" ", ' ', $value));
         $value = $value !== '' ? $value : null;
         $translation->value = $value;
         $translation->status = $translation->isDirty() && $value != $translation->saved_value ? Translation::STATUS_CHANGED : Translation::STATUS_SAVED;
         $translation->save();
     }
     return array('status' => 'ok');
 }