public function updateTranslation(Request $request) { $lang_id = $request->get('lang_id'); //return $lang_id; die(); foreach ($lang_id as $id => $translation) { //return $id; die(); $translate = Translation::find($id); //return $translate;die(); if (!is_null($translate)) { //this is original or translated if (!is_null($translate->translation_id)) { //this is translated $original = $translate->original; } else { //this is original $original = $translate; } //return $original; die(); //$original->translated()->delete(); foreach ($translation as $lang => $string) { $locale = Locale::where('code', $lang)->first(); $child = Translation::firstOrNew(['locale_id' => $locale->id, 'translation_id' => $original->id]); $child->translation = $string; $child->original()->dissociate(); $child->locale()->dissociate(); $child->original()->associate($original); $child->locale()->associate($locale); $child->save(); } } else { $json['message'] = 'Something wrong!'; } } $json['status'] = true; $json['message'] = 'Translation updated!'; return json_encode($json); }
public function addLocale($locale) { $localeId = \App\Locale::where('lang', $locale)->first()->id; \Auth::user()->locales()->attach($localeId); }