Esempio n. 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $data = $request->all();
     $langs = get_langs();
     //return $langs;
     DB::beginTransaction();
     try {
         $com = new Service();
         $com->value = $data['value'];
         $com->option = $data['option'];
         $com->choice = $data['choice'];
         $com->save();
         foreach ($langs as $lang) {
             $code = $data[$lang->code];
             $valid = \Validator::make($code, ['name' => 'required']);
             if ($valid->fails()) {
                 DB::rollBack();
                 return redirect()->back()->withErrors($valid)->withInput();
             }
             $name = $code['name'];
             $com_lang = ['name' => $name];
             //return $com_lang;
             $com->langs()->attach($lang->id, $com_lang);
         }
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back()->withInput()->with('errorMess', 'Có lỗi xảy ra!');
     }
     DB::commit();
     return redirect()->route('admin.services.index')->with('Mess', 'Thêm thành công');
 }