예제 #1
0
 public function translation(Request $request)
 {
     //1. Validation
     $this->validate($request, ['title' => 'required', 'content_id' => 'required|numeric', 'language_id' => 'required|max:2', 'content' => 'required']);
     //2. Find menu by id
     $content = Content::firstOrNew(['id' => $request->input('content_id')]);
     try {
         if ($content->exists) {
             $contentTranslation = ContentTranslation::firstOrNew($request->only('content_id', 'language_id'));
             if (!$contentTranslation->exists) {
                 $contentTranslation = new ContentTranslation($request->all());
                 $contentTranslation->save();
                 //5. FLASH MESSAGE BACK
                 Session::flash('flash_message', 'Content successfully translated!');
             } else {
                 $contentTranslation::where('content_id', $request->input('content_id'))->where('language_id', $request->input('language_id'))->update($request->only('content', 'title', 'images'));
                 //5. FLASH MESSAGE BACK
                 Session::flash('flash_message', 'Content successfully translate updated!');
             }
         } else {
             //5. FLASH MESSAGE BACK
             Session::flash('flash_message', 'Content not found!!!');
         }
     } catch (Exception $e) {
     }
     //6. REDIRECT BACK
     return redirect()->back();
 }